

    THUMB
    REQUIRE8
    PRESERVE8

    AREA |.text|, CODE, READONLY, ALIGN=2

    ; Reference to the FailSafe routine to be executed in case of non-recoverable
    ; failure

    ; C variables for control flow monitoring

    IMPORT U32_MARCH_DB
    IMPORT U32_MARCH_DB_BAR

;*******************************************************************************
;                  Note: when possible, BRANCH are 16-bit only (depending on
;                  relative offset to final BL instruction)
; Input          : None.
; Output         : Branch directly to a Fail Safe routine in case of failure
; Return         : CPUTEST_SUCCESS (=1) if test is ok
;*******************************************************************************/
; ---------inter word test-------------------
; march SS-0 ∧, W0
; march SS-1 ∨, RRWRW, DB[0u], DB[0u], DB_BAR[0u]
_diag_gpr_step1 PROC
    EXPORT _diag_gpr_step1

    PUSH {R4-R7}           ; Safe registers
    
    MRS R0, PRIMASK
    PUSH {R0}
    
    CPSID I

    LDR R0, =U32_MARCH_DB
    LDR R1,[R0]
    LDR R2,[R0]
    LDR R3,[R0]
    LDR R4,[R0]
    LDR R5,[R0]
    LDR R6,[R0]
    LDR R7,[R0]
    LDR R0, =U32_MARCH_DB
    LDR R0,[R0]
    MOV R8,R0
    LDR R0, =U32_MARCH_DB
    LDR R0,[R0]
    MOV R9,R0
    LDR R0, =U32_MARCH_DB
    LDR R0,[R0]
    MOV R10,R0
    LDR R0, =U32_MARCH_DB
    LDR R0,[R0]
    MOV R11,R0
    LDR R0, =U32_MARCH_DB
    LDR R0,[R0]
    MOV R12,R0
    
    LDR R0, =U32_MARCH_DB
    LDR R0, [R0]
    CMP R0, R12
    BNE gpr_step1_test_fail
    LDR R0, =U32_MARCH_DB_BAR
    LDR R0, [R0]
    MOV R12,R0
    
    LDR R0, =U32_MARCH_DB
    LDR R0, [R0]
    CMP R0, R11
    BNE gpr_step1_test_fail
    LDR R0, =U32_MARCH_DB_BAR
    LDR R0, [R0]
    MOV R11,R0
    
    LDR R0, =U32_MARCH_DB
    LDR R0, [R0]
    CMP R0, R10
    BNE gpr_step1_test_fail
    LDR R0, =U32_MARCH_DB_BAR
    LDR R0, [R0]
    MOV R10,R0
    
    LDR R0, =U32_MARCH_DB
    LDR R0, [R0]
    CMP R0, R9
    BNE gpr_step1_test_fail
    LDR R0, =U32_MARCH_DB_BAR
    LDR R0, [R0]
    MOV R9,R0
    
    LDR R0, =U32_MARCH_DB
    LDR R0, [R0]
    CMP R0, R8
    BNE gpr_step1_test_fail
    LDR R0, =U32_MARCH_DB_BAR
    LDR R0, [R0]
    MOV R8,R0
    
    LDR R0, =U32_MARCH_DB
    LDR R0, [R0]
    CMP R0, R7
    BNE gpr_step1_test_fail
    LDR R0, =U32_MARCH_DB_BAR
    LDR R7,[R0]

    LDR R0, =U32_MARCH_DB
    LDR R0, [R0]
    CMP R0, R6
    BNE gpr_step1_test_fail
    LDR R0, =U32_MARCH_DB_BAR
    LDR R6,[R0]

    LDR R0, =U32_MARCH_DB
    LDR R0, [R0]
    CMP R0, R5
    BNE gpr_step1_test_fail
    LDR R0, =U32_MARCH_DB_BAR
    LDR R5,[R0]
    
    LDR R0, =U32_MARCH_DB
    LDR R0, [R0]
    CMP R0, R4
    BNE gpr_step1_test_fail
    LDR R0, =U32_MARCH_DB_BAR
    LDR R4,[R0]
    
    LDR R0, =U32_MARCH_DB
    LDR R0, [R0]
    CMP R0, R3
    BNE gpr_step1_test_fail
    LDR R0, =U32_MARCH_DB_BAR
    LDR R3,[R0]
    
    LDR R0, =U32_MARCH_DB
    LDR R0, [R0]
    CMP R0, R2
    BNE gpr_step1_test_fail
    LDR R0, =U32_MARCH_DB_BAR
    LDR R2,[R0]
    
    LDR R0, =U32_MARCH_DB
    LDR R0, [R0]
    CMP R0, R1
    BNE gpr_step1_test_fail
    LDR R0, =U32_MARCH_DB_BAR
    LDR R1,[R0]
    
    LDR R0, =U32_MARCH_DB_BAR
    LDR R0,[R0]
    
    ; Link register R14 cannot be tested an error should be detected by Ctrl flow test later
    
    POP {R0}
    MSR PRIMASK, R0
    
    POP {R4-R7}     ; Restore registers
    MOVS R0, #0x00  ; CPUTEST_SUCCESS
    BX LR           ; return to the caller
    
gpr_step1_test_fail
    POP {R0}
    MSR PRIMASK, R0
    POP {R4-R7}     ; Restore registers
    MOVS R0, #0x01  ; CPUTEST_FAIL
    BX LR           ; return to the caller
    
    ENDP            ; routine (unrecoverable fault)

; ---------inter word test-------------------
; march SS-2 ∧, RRWRW, DB_BAR[0u], DB_BAR[0u], DB[0u]
_diag_gpr_step2 PROC
    EXPORT _diag_gpr_step2

    PUSH {R4-R7}           ; Safe registers
    
    MRS R0, PRIMASK
    PUSH {R0}
    
    CPSID I

    LDR R0, =U32_MARCH_DB_BAR
    LDR R0,[R0]
    MOV R1,R0
    MOV R2,R0
    MOV R3,R0
    MOV R4,R0
    MOV R5,R0
    MOV R6,R0
    MOV R7,R0
    MOV R8,R0
    MOV R9,R0
    MOV R10,R0
    MOV R11,R0
    MOV R12,R0

    CMP  R0, R1
    BNE  gpr_step2_test_fail
    MVNS R1, R0

    CMP R0, R2
    BNE gpr_step2_test_fail
    MVNS R2,R0

    CMP R0, R3
    BNE gpr_step2_test_fail
    MVNS R3,R0
    
    CMP R0, R4
    BNE gpr_step2_test_fail
    MVNS R4,R0
    
    CMP R0, R5
    BNE gpr_step2_test_fail
    MVNS R5,R0
    
    CMP R0, R6
    BNE gpr_step2_test_fail
    MVNS R6,R0
    
    CMP R0, R7
    BNE gpr_step2_test_fail
    MVNS R7,R0
    
    CMP R0, R8
    BNE gpr_step2_test_fail
    MOV R8,R2
    
    CMP R0, R9
    BNE gpr_step2_test_fail
    MOV R9,R2
    
    CMP R0, R10
    BNE gpr_step2_test_fail
    MOV R10,R2
    
    CMP R0, R11
    BNE gpr_step2_test_fail
    MOV R11,R2
    
    CMP R0, R12
    BNE gpr_step2_test_fail
    MOV R12,R2
    
    POP {R0}
    MSR PRIMASK, R0
    POP {R4-R7}     ; Restore registers
    MOVS R0, #0x00  ; CPUTEST_SUCCESS
    BX LR           ; return to the caller
    
gpr_step2_test_fail
    POP {R0}
    MSR PRIMASK, R0
    POP {R4-R7}     ; Restore registers
    MOVS R0, #0x01  ; CPUTEST_FAIL
    BX LR           ; return to the caller
    
    ENDP            ; routine (unrecoverable fault)

; ---------inter word test-------------------
; march SS-3 ∧, RRWRW, DB[0u], DB[0u], DB_BAR[0u]
_diag_gpr_step3 PROC
    EXPORT _diag_gpr_step3

    PUSH {R4-R7}           ; Safe registers
    
    MRS R0, PRIMASK
    PUSH {R0}
    
    CPSID I

    LDR R0, =U32_MARCH_DB
    LDR R0,[R0]
    MOV R1,R0
    MOV R2,R0
    MOV R3,R0
    MOV R4,R0
    MOV R5,R0
    MOV R6,R0
    MOV R7,R0
    MOV R8,R0
    MOV R9,R0
    MOV R10,R0
    MOV R11,R0
    MOV R12,R0

    CMP  R0, R1
    BNE  gpr_step3_test_fail
    CMP  R0, R1
    BNE  gpr_step3_test_fail
    MOV  R1, R0
    CMP  R0, R1
    BNE  gpr_step3_test_fail
    MVNS R1, R0
    
    CMP  R0, R2
    BNE  gpr_step3_test_fail
    CMP  R0, R2
    BNE  gpr_step3_test_fail
    MOV  R2, R0
    CMP  R0, R2
    BNE  gpr_step3_test_fail
    MVNS R2, R0
    
    CMP  R0, R3
    BNE  gpr_step3_test_fail
    CMP  R0, R3
    BNE  gpr_step3_test_fail
    MOV  R3, R0
    CMP  R0, R3
    BNE  gpr_step3_test_fail
    MVNS R3, R0

    CMP  R0, R4
    BNE  gpr_step3_test_fail
    CMP  R0, R4
    BNE  gpr_step3_test_fail
    MOV  R4, R0
    CMP  R0, R4
    BNE  gpr_step3_test_fail
    MVNS R4, R0
    
    CMP  R0, R5
    BNE  gpr_step3_test_fail
    CMP  R0, R5
    BNE  gpr_step3_test_fail
    MOV  R5, R0
    CMP  R0, R5
    BNE  gpr_step3_test_fail
    MVNS R5, R0
    
    CMP  R0, R6
    BNE  gpr_step3_test_fail
    CMP  R0, R6
    BNE  gpr_step3_test_fail
    MOV  R6, R0
    CMP  R0, R6
    BNE  gpr_step3_test_fail
    MVNS R6, R0
    
    CMP  R0, R7
    BNE  gpr_step3_test_fail
    CMP  R0, R7
    BNE  gpr_step3_test_fail
    MOV  R7, R0
    CMP  R0, R7
    BNE  gpr_step3_test_fail
    MVNS R7, R0
    
    CMP  R0, R8
    BNE  gpr_step3_test_fail
    CMP  R0, R8
    BNE  gpr_step3_test_fail
    MOV  R8, R0
    CMP  R0, R8
    BNE  gpr_step3_test_fail
    MOV  R8, R6
    
    CMP  R0, R9
    BNE  gpr_step3_test_fail
    CMP  R0, R9
    BNE  gpr_step3_test_fail
    MOV  R9, R0
    CMP  R0, R9
    BNE  gpr_step3_test_fail
    MOV  R9, R6
    
    CMP  R0, R10
    BNE  gpr_step3_test_fail
    CMP  R0, R10
    BNE  gpr_step3_test_fail
    MOV  R10, R0
    CMP  R0, R10
    BNE  gpr_step3_test_fail
    MOV  R10, R6
    
    CMP  R0, R11
    BNE  gpr_step3_test_fail
    CMP  R0, R11
    BNE  gpr_step3_test_fail
    MOV  R11, R0
    CMP  R0, R11
    BNE  gpr_step3_test_fail
    MOV  R11, R6
    
    CMP  R0, R12
    BNE  gpr_step3_test_fail
    CMP  R0, R12
    BNE  gpr_step3_test_fail
    MOV  R12, R0
    CMP  R0, R12
    BNE  gpr_step3_test_fail
    MOV  R12, R6
    
		NOP;
    POP {R0}
    MSR PRIMASK, R0
    POP {R4-R7}     ; Restore registers
    MOVS R0, #0x00  ; CPUTEST_SUCCESS
    BX LR           ; return to the caller

    LTORG
gpr_step3_test_fail
    POP {R0}
    MSR PRIMASK, R0
    POP {R4-R7}     ; Restore registers
    MOVS R0, #0x01  ; CPUTEST_FAIL
    BX LR           ; return to the caller

    
    ENDP            ; routine (unrecoverable fault)

; ---------inter word test-------------------
; march SS-4 ∧, RRWRRW, DB_BAR[0u], DB_BAR[0u], DB[0u]
_diag_gpr_step4 PROC
    EXPORT _diag_gpr_step4

    PUSH {R4-R7}           ; Safe registers
    
    MRS R0, PRIMASK
    PUSH {R0}
    
    CPSID I

    LDR R0, =U32_MARCH_DB_BAR
    LDR R0,[R0]
    MOV R1,R0
    MOV R2,R0
    MOV R3,R0
    MOV R4,R0
    MOV R5,R0
    MOV R6,R0
    MOV R7,R0
    MOV R8,R0
    MOV R9,R0
    MOV R10,R0
    MOV R11,R0
    MOV R12,R0

    CMP  R0, R1
    BNE  gpr_step4_test_fail
    CMP  R0, R1
    BNE  gpr_step4_test_fail
    MOV  R1, R0
    CMP  R0, R1
    BNE  gpr_step4_test_fail
    CMP  R0, R1
    BNE  gpr_step4_test_fail
    MVNS R1, R0
    
    CMP  R0, R2
    BNE  gpr_step4_test_fail
    CMP  R0, R2
    BNE  gpr_step4_test_fail
    MOV  R2, R0
    CMP  R0, R2
    BNE  gpr_step4_test_fail
    CMP  R0, R2
    BNE  gpr_step4_test_fail
    MVNS R2, R0
    
    CMP  R0, R3
    BNE  gpr_step4_test_fail
    CMP  R0, R3
    BNE  gpr_step4_test_fail
    MOV  R3, R0
    CMP  R0, R3
    BNE  gpr_step4_test_fail
    CMP  R0, R3
    BNE  gpr_step4_test_fail
    MVNS R3, R0

    CMP  R0, R4
    BNE  gpr_step4_test_fail
    CMP  R0, R4
    BNE  gpr_step4_test_fail
    MOV  R4, R0
    CMP  R0, R4
    BNE  gpr_step4_test_fail
    CMP  R0, R4
    BNE  gpr_step4_test_fail
    MVNS R4, R0
    
    CMP  R0, R5
    BNE  gpr_step4_test_fail
    CMP  R0, R5
    BNE  gpr_step4_test_fail
    MOV  R5, R0
    CMP  R0, R5
    BNE  gpr_step4_test_fail
    CMP  R0, R5
    BNE  gpr_step4_test_fail
    MVNS R5, R0
    
    CMP  R0, R6
    BNE  gpr_step4_test_fail
    CMP  R0, R6
    BNE  gpr_step4_test_fail
    MOV  R6, R0
    CMP  R0, R6
    BNE  gpr_step4_test_fail
    CMP  R0, R6
    BNE  gpr_step4_test_fail
    MVNS R6, R0
    
    CMP  R0, R7
    BNE  gpr_step4_test_fail
    CMP  R0, R7
    BNE  gpr_step4_test_fail
    MOV  R7, R0
    CMP  R0, R7
    BNE  gpr_step4_test_fail
    CMP  R0, R7
    BNE  gpr_step4_test_fail
    MVNS R7, R0
    
    CMP  R0, R8
    BNE  gpr_step4_test_fail
    CMP  R0, R8
    BNE  gpr_step4_test_fail
    MOV  R8, R0
    CMP  R0, R8
    BNE  gpr_step4_test_fail
    CMP  R0, R8
    BNE  gpr_step4_test_fail
    MOV  R8, R1
    
    CMP  R0, R9
    BNE  gpr_step4_test_fail
    CMP  R0, R9
    BNE  gpr_step4_test_fail
    MOV  R9, R0
    CMP  R0, R9
    BNE  gpr_step4_test_fail
    CMP  R0, R9
    BNE  gpr_step4_test_fail
    MOV  R9, R1
    
    CMP  R0, R10
    BNE  gpr_step4_test_fail
    CMP  R0, R10
    BNE  gpr_step4_test_fail
    MOV  R10, R0
    CMP  R0, R10
    BNE  gpr_step4_test_fail
    CMP  R0, R10
    BNE  gpr_step4_test_fail
    MOV  R10, R1
    
    CMP  R0, R11
    BNE  gpr_step4_test_fail
    CMP  R0, R11
    BNE  gpr_step4_test_fail
    MOV  R11, R0
    CMP  R0, R11
    BNE  gpr_step4_test_fail
    CMP  R0, R11
    BNE  gpr_step4_test_fail
    MOV  R11, R1
    
    CMP  R0, R12
    BNE  gpr_step4_test_fail
    CMP  R0, R12
    BNE  gpr_step4_test_fail
    MOV  R12, R0
    CMP  R0, R12
    BNE  gpr_step4_test_fail
    CMP  R0, R12
    BNE  gpr_step4_test_fail
    MOV  R12, R1
    
    POP {R0}
    MSR PRIMASK, R0
    POP {R4-R7}     ; Restore registers
    MOVS R0, #0x00  ; CPUTEST_SUCCESS
    BX LR           ; return to the caller
    
gpr_step4_test_fail
    POP {R0}
    MSR PRIMASK, R0
    POP {R4-R7}     ; Restore registers
    MOVS R0, #0x01  ; CPUTEST_FAIL
    BX LR           ; return to the caller
    
    ENDP            ; routine (unrecoverable fault)
    
; ---------intra word test-------------------
; march SS-5 ∧, RWWR, DB[0u], DB_BAR[1u], DB[1u]
_diag_gpr_step5 PROC
    EXPORT _diag_gpr_step5

    PUSH {R4-R7}           ; Safe registers
    
    MRS R0, PRIMASK
    PUSH {R0}
    
    CPSID I

    LDR R0, =U32_MARCH_DB
    LDR R0,[R0]
    MOV R1,R0
    MOV R2,R0
    MOV R3,R0
    MOV R4,R0
    MOV R5,R0
    MOV R6,R0
    MOV R7,R0
    MOV R8,R0
    MOV R9,R0
    MOV R10,R0
    MOV R11,R0
    MOV R12,R0

    CMP  R0, R1
    BNE  gpr_step5_test_fail
    CMP  R0, R2
    BNE  gpr_step5_test_fail
    CMP  R0, R3
    BNE  gpr_step5_test_fail
    CMP  R0, R4
    BNE  gpr_step5_test_fail
    CMP  R0, R5
    BNE  gpr_step5_test_fail
    CMP  R0, R6
    BNE  gpr_step5_test_fail
    CMP  R0, R7
    BNE  gpr_step5_test_fail
    CMP  R0, R8
    BNE  gpr_step5_test_fail
    CMP  R0, R9
    BNE  gpr_step5_test_fail
    CMP  R0, R10
    BNE  gpr_step5_test_fail
    CMP  R0, R11
    BNE  gpr_step5_test_fail
    CMP  R0, R12
    BNE  gpr_step5_test_fail

    LDR  R0, =U32_MARCH_DB
    LDR  R0, [R0, #4]
    
    MVNS R1, R0
    MOV  R1, R0
    CMP  R0, R1
    BNE  gpr_step5_test_fail
    
    MVNS R2, R0
    MOV  R2, R0
    CMP  R0, R2
    BNE  gpr_step5_test_fail
    
    MVNS R3, R0
    MOV  R3, R0
    CMP  R0, R3
    BNE  gpr_step5_test_fail
    
    MVNS R4, R0
    MOV  R4, R0
    CMP  R0, R4
    BNE  gpr_step5_test_fail
    
    MVNS R5, R0
    MOV  R5, R0
    CMP  R0, R5
    BNE  gpr_step5_test_fail
    
    MVNS R6, R0
    MOV  R6, R0
    CMP  R0, R6
    BNE  gpr_step5_test_fail
    
    MVNS R7, R0
    MOV  R7, R0
    CMP  R0, R7
    BNE  gpr_step5_test_fail
    
    MVNS R2, R0
    MOV  R8, R2
    MOV  R8, R0
    CMP  R0, R8
    BNE  gpr_step5_test_fail
    
    MOV  R9, R2
    MOV  R9, R0
    CMP  R0, R9
    BNE  gpr_step5_test_fail
    
    MOV  R10, R2
    MOV  R10, R0
    CMP  R0, R10
    BNE  gpr_step5_test_fail
    
    MOV  R11, R2
    MOV  R11, R0
    CMP  R0, R11
    BNE  gpr_step5_test_fail
    
    MOV  R12, R2
    MOV  R12, R0
    CMP  R0, R12
    BNE  gpr_step5_test_fail
    
    POP {R0}
    MSR PRIMASK, R0
    POP {R4-R7}     ; Restore registers
    MOVS R0, #0x00  ; CPUTEST_SUCCESS
    BX LR           ; return to the caller

gpr_step5_test_fail
    POP {R0}
    MSR PRIMASK, R0
    POP {R4-R7}     ; Restore registers
    MOVS R0, #0x01  ; CPUTEST_FAIL
    BX LR           ; return to the caller
    ENDP            ; routine (unrecoverable fault)

; ---------intra word test-------------------
; march SS-6 ∨, RWR, DB[1u], DB_BAR[1u]
_diag_gpr_step6 PROC
    EXPORT _diag_gpr_step6

    PUSH {R4-R7}           ; Safe registers
    
    MRS R0, PRIMASK
    PUSH {R0}
    
    CPSID I

    LDR R0, =U32_MARCH_DB
    LDR R0,[R0, #4]
    MOV R1,R0
    MOV R2,R0
    MOV R3,R0
    MOV R4,R0
    MOV R5,R0
    MOV R6,R0
    MOV R7,R0
    MOV R8,R0
    MOV R9,R0
    MOV R10,R0
    MOV R11,R0
    MOV R12,R0

    CMP  R0, R12
    BNE  gpr_step6_test_fail
    MVNS R0, R0
    MOV  R12, R0
    CMP  R0, R12
    BNE  gpr_step6_test_fail
    MVNS R0, R0
    
    CMP  R0, R11
    BNE  gpr_step6_test_fail
    MVNS R0, R0
    MOV  R11, R0
    CMP  R0, R11
    BNE  gpr_step6_test_fail
    MVNS R0, R0
    
    CMP  R0, R10
    BNE  gpr_step6_test_fail
    MVNS R0, R0
    MOV  R10, R0
    CMP  R0, R10
    BNE  gpr_step6_test_fail
    MVNS R0, R0
    
    CMP  R0, R9
    BNE  gpr_step6_test_fail
    MVNS R0, R0
    MOV  R9, R0
    CMP  R0, R9
    BNE  gpr_step6_test_fail
    MVNS R0, R0
    
    CMP  R0, R8
    BNE  gpr_step6_test_fail
    MVNS R0, R0
    MOV  R8, R0
    CMP  R0, R8
    BNE  gpr_step6_test_fail
    MVNS R0, R0
    
    CMP  R0, R7
    BNE  gpr_step6_test_fail
    MVNS R0, R0
    MOV  R7, R0
    CMP  R0, R7
    BNE  gpr_step6_test_fail
    MVNS R0, R0
    
    CMP  R0, R6
    BNE  gpr_step6_test_fail
    MVNS R0, R0
    MOV  R6, R0
    CMP  R0, R6
    BNE  gpr_step6_test_fail
    MVNS R0, R0
    
    CMP  R0, R5
    BNE  gpr_step6_test_fail
    MVNS R0, R0
    MOV  R5, R0
    CMP  R0, R5
    BNE  gpr_step6_test_fail
    MVNS R0, R0
    
    CMP  R0, R4
    BNE  gpr_step6_test_fail
    MVNS R0, R0
    MOV  R4, R0
    CMP  R0, R4
    BNE  gpr_step6_test_fail
    MVNS R0, R0
    
    CMP  R0, R3
    BNE  gpr_step6_test_fail
    MVNS R0, R0
    MOV  R3, R0
    CMP  R0, R3
    BNE  gpr_step6_test_fail
    MVNS R0, R0
    
    CMP  R0, R2
    BNE  gpr_step6_test_fail
    MVNS R0, R0
    MOV  R2, R0
    CMP  R0, R2
    BNE  gpr_step6_test_fail
    MVNS R0, R0
    
    CMP  R0, R1
    BNE  gpr_step6_test_fail
    MVNS R0, R0
    MOV  R1, R0
    CMP  R0, R1
    BNE  gpr_step6_test_fail
    MVNS R0, R0
    
    POP {R0}
    MSR PRIMASK, R0
    POP {R4-R7}     ; Restore registers
    MOVS R0, #0x00  ; CPUTEST_SUCCESS
    BX LR           ; return to the caller
    LTORG
gpr_step6_test_fail
    POP {R0}
    MSR PRIMASK, R0
    POP {R4-R7}     ; Restore registers
    MOVS R0, #0x01  ; CPUTEST_FAIL
    BX LR           ; return to the caller

    ENDP            ; routine (unrecoverable fault)
    
; ---------intra word test-------------------
; march SS-7 ∧, RWWR, DB_BAR[1u], DB_BAR[2u], DB[2u],
_diag_gpr_step7 PROC
    EXPORT _diag_gpr_step7

    PUSH {R4-R7}           ; Safe registers
    
    MRS R0, PRIMASK
    PUSH {R0}
    
    CPSID I

    LDR R0, =U32_MARCH_DB_BAR
    LDR R0,[R0, #4]
    MOV R1,R0
    MOV R2,R0
    MOV R3,R0
    MOV R4,R0
    MOV R5,R0
    MOV R6,R0
    MOV R7,R0
    MOV R8,R0
    MOV R9,R0
    MOV R10,R0
    MOV R11,R0
    MOV R12,R0
    
    CMP  R0, R1
    BNE  gpr_step7_test_fail
    LDR  R0, =U32_MARCH_DB_BAR
    LDR  R0,[R0, #8]
    MOV  R1, R0
    MVNS R0, R0
    MOV  R1, R0
    CMP  R0, R1
    BNE  gpr_step7_test_fail
    MVNS R0, R0
    
    LDR  R0, =U32_MARCH_DB_BAR
    LDR  R1,[R0, #4]
    LDR  R0, =U32_MARCH_DB_BAR
    LDR  R0,[R0, #8]
	
    CMP  R1, R2
    BNE  gpr_step7_test_fail
    MOV  R2, R0
    MVNS R0, R0
    MOV  R2, R0
    CMP  R0, R2
    BNE  gpr_step7_test_fail
    MVNS R0, R0
    
    CMP  R1, R3
    BNE  gpr_step7_test_fail
    MOV  R3, R0
    MVNS R0, R0
    MOV  R3, R0
    CMP  R0, R3
    BNE  gpr_step7_test_fail
    MVNS R0, R0
    
    CMP  R1, R4
    BNE  gpr_step7_test_fail
    MOV  R4, R0
    MVNS R0, R0
    MOV  R4, R0
    CMP  R0, R4
    BNE  gpr_step7_test_fail
    MVNS R0, R0
    
    CMP  R1, R5
    BNE  gpr_step7_test_fail
    MOV  R5, R0
    MVNS R0, R0
    MOV  R5, R0
    CMP  R0, R5
    BNE  gpr_step7_test_fail
    MVNS R0, R0
    
    CMP  R1, R6
    BNE  gpr_step7_test_fail
    MOV  R6, R0
    MVNS R0, R0
    MOV  R6, R0
    CMP  R0, R6
    BNE  gpr_step7_test_fail
    MVNS R0, R0
    
    CMP  R1, R7
    BNE  gpr_step7_test_fail
    MOV  R7, R0
    MVNS R0, R0
    MOV  R7, R0
    CMP  R0, R7
    BNE  gpr_step7_test_fail
    MVNS R0, R0
    
    CMP  R1, R8
    BNE  gpr_step7_test_fail
    MOV  R8, R0
    MVNS R0, R0
    MOV  R8, R0
    CMP  R0, R8
    BNE  gpr_step7_test_fail
    MVNS R0, R0
    
    CMP  R1, R9
    BNE  gpr_step7_test_fail
    MOV  R9, R0
    MVNS R0, R0
    MOV  R9, R0
    CMP  R0, R9
    BNE  gpr_step7_test_fail
    MVNS R0, R0

    CMP  R1, R10
    BNE  gpr_step7_test_fail
    MOV  R10, R0
    MVNS R0, R0
    MOV  R10, R0
    CMP  R0, R10
    BNE  gpr_step7_test_fail
    MVNS R0, R0
    
    CMP  R1, R11
    BNE  gpr_step7_test_fail
    MOV  R11, R0
    MVNS R0, R0
    MOV  R11, R0
    CMP  R0, R11
    BNE  gpr_step7_test_fail
    MVNS R0, R0
    
    CMP  R1, R12
    BNE  gpr_step7_test_fail
    MOV  R12, R0
    MVNS R0, R0
    MOV  R12, R0
    CMP  R0, R12
    BNE  gpr_step7_test_fail
    MVNS R0, R0
    
    POP {R0}
    MSR PRIMASK, R0
    POP {R4-R7}     ; Restore registers
    MOVS R0, #0x00  ; CPUTEST_SUCCESS
    BX LR           ; return to the caller

gpr_step7_test_fail
    POP {R0}
    MSR PRIMASK, R0
    POP {R4-R7}     ; Restore registers
    MOVS R0, #0x01  ; CPUTEST_FAIL
    BX LR           ; return to the caller

    ENDP            ; routine (unrecoverable fault)

; ---------intra word test-------------------
; march SS-8 ∨, RWR, DB[2u], DB_BAR[2u]
_diag_gpr_step8 PROC
    EXPORT _diag_gpr_step8

    PUSH {R4-R7}           ; Safe registers
    
    MRS R0, PRIMASK
    PUSH {R0}
    
    CPSID I

    LDR R0, =U32_MARCH_DB
    LDR R0,[R0, #8]
    MOV R1,R0
    MOV R2,R0
    MOV R3,R0
    MOV R4,R0
    MOV R5,R0
    MOV R6,R0
    MOV R7,R0
    MOV R8,R0
    MOV R9,R0
    MOV R10,R0
    MOV R11,R0
    MOV R12,R0
    
    CMP  R0, R12
    BNE  gpr_step8_test_fail
    MVNS R0, R0
    MOV  R12, R0
    CMP  R0, R12
    BNE  gpr_step8_test_fail
    MVNS R0, R0
    
    CMP  R0, R11
    BNE  gpr_step8_test_fail
    MVNS R0, R0
    MOV  R11, R0
    CMP  R0, R11
    BNE  gpr_step8_test_fail
    MVNS R0, R0
    
    CMP  R0, R10
    BNE  gpr_step8_test_fail
    MVNS R0, R0
    MOV  R10, R0
    CMP  R0, R10
    BNE  gpr_step8_test_fail
    MVNS R0, R0
    
    CMP  R0, R9
    BNE  gpr_step8_test_fail
    MVNS R0, R0
    MOV  R9, R0
    CMP  R0, R9
    BNE  gpr_step8_test_fail
    MVNS R0, R0
    
    CMP  R0, R8
    BNE  gpr_step8_test_fail
    MVNS R0, R0
    MOV  R8, R0
    CMP  R0, R8
    BNE  gpr_step8_test_fail
    MVNS R0, R0
    
    CMP  R0, R7
    BNE  gpr_step8_test_fail
    MVNS R0, R0
    MOV  R7, R0
    CMP  R0, R7
    BNE  gpr_step8_test_fail
    MVNS R0, R0
    
    CMP  R0, R6
    BNE  gpr_step8_test_fail
    MVNS R0, R0
    MOV  R6, R0
    CMP  R0, R6
    BNE  gpr_step8_test_fail
    MVNS R0, R0
    
    CMP  R0, R5
    BNE  gpr_step8_test_fail
    MVNS R0, R0
    MOV  R5, R0
    CMP  R0, R5
    BNE  gpr_step8_test_fail
    MVNS R0, R0
    
    CMP  R0, R4
    BNE  gpr_step8_test_fail
    MVNS R0, R0
    MOV  R4, R0
    CMP  R0, R4
    BNE  gpr_step8_test_fail
    MVNS R0, R0

    CMP  R0, R3
    BNE  gpr_step8_test_fail
    MVNS R0, R0
    MOV  R3, R0
    CMP  R0, R3
    BNE  gpr_step8_test_fail
    MVNS R0, R0
    
    CMP  R0, R2
    BNE  gpr_step8_test_fail
    MVNS R0, R0
    MOV  R2, R0
    CMP  R0, R2
    BNE  gpr_step8_test_fail
    MVNS R0, R0
    
    CMP  R0, R1
    BNE  gpr_step8_test_fail
    MVNS R0, R0
    MOV  R1, R0
    CMP  R0, R1
    BNE  gpr_step8_test_fail
    MVNS R0, R0
    
    POP {R0}
    MSR PRIMASK, R0
    POP {R4-R7}     ; Restore registers
    MOVS R0, #0x00  ; CPUTEST_SUCCESS
    BX LR           ; return to the caller
    LTORG
gpr_step8_test_fail
    POP {R0}
    MSR PRIMASK, R0
    POP {R4-R7}     ; Restore registers
    MOVS R0, #0x01  ; CPUTEST_FAIL
    BX LR           ; return to the caller

    ENDP            ; routine (unrecoverable fault)
    
; ---------intra word test-------------------
; march SS-9 ∧, RWWR, DB_BAR[2u], DB_BAR[3u], DB[3u]
_diag_gpr_step9 PROC
    EXPORT _diag_gpr_step9

    PUSH {R4-R7}           ; Safe registers
    
    MRS R0, PRIMASK
    PUSH {R0}
    
    CPSID I

    LDR R0, =U32_MARCH_DB_BAR
    LDR R0,[R0, #8]
    MOV R1,R0
    MOV R2,R0
    MOV R3,R0
    MOV R4,R0
    MOV R5,R0
    MOV R6,R0
    MOV R7,R0
    MOV R8,R0
    MOV R9,R0
    MOV R10,R0
    MOV R11,R0
    MOV R12,R0
    
    CMP  R0, R1
    BNE  gpr_step9_test_fail
    LDR  R0, =U32_MARCH_DB_BAR
    LDR  R0,[R0, #12]
    MOV  R1, R0
    MVNS R0, R0
    MOV  R1, R0
    CMP  R0, R1
    BNE  gpr_step9_test_fail
    MVNS R0, R0
    
    LDR R0, =U32_MARCH_DB_BAR
    LDR R1,[R0, #8]
    LDR  R0, =U32_MARCH_DB_BAR
    LDR  R0,[R0, #12]
	
    CMP  R1, R2
    BNE  gpr_step9_test_fail
    MOV  R2, R0
    MVNS R0, R0
    MOV  R2, R0
    CMP  R0, R2
    BNE  gpr_step9_test_fail
    MVNS R0, R0
    
    CMP  R1, R3
    BNE  gpr_step9_test_fail
    MOV  R3, R0
    MVNS R0, R0
    MOV  R3, R0
    CMP  R0, R3
    BNE  gpr_step9_test_fail
    MVNS R0, R0
    
    CMP  R1, R4
    BNE  gpr_step9_test_fail
    MOV  R4, R0
    MVNS R0, R0
    MOV  R4, R0
    CMP  R0, R4
    BNE  gpr_step9_test_fail
    MVNS R0, R0
    
    CMP  R1, R5
    BNE  gpr_step9_test_fail
    MOV  R5, R0
    MVNS R0, R0
    MOV  R5, R0
    CMP  R0, R5
    BNE  gpr_step9_test_fail
    MVNS R0, R0
    
    CMP  R1, R6
    BNE  gpr_step9_test_fail
    MOV  R6, R0
    MVNS R0, R0
    MOV  R6, R0
    CMP  R0, R6
    BNE  gpr_step9_test_fail
    MVNS R0, R0
    
    CMP  R1, R7
    BNE  gpr_step9_test_fail
    MOV  R7, R0
    MVNS R0, R0
    MOV  R7, R0
    CMP  R0, R7
    BNE  gpr_step9_test_fail
    MVNS R0, R0
    
    CMP  R1, R8
    BNE  gpr_step9_test_fail
    MOV  R8, R0
    MVNS R0, R0
    MOV  R8, R0
    CMP  R0, R8
    BNE  gpr_step9_test_fail
    MVNS R0, R0
    
    CMP  R1, R9
    BNE  gpr_step9_test_fail
    MOV  R9, R0
    MVNS R0, R0
    MOV  R9, R0
    CMP  R0, R9
    BNE  gpr_step9_test_fail
    MVNS R0, R0

    CMP  R1, R10
    BNE  gpr_step9_test_fail
    MOV  R10, R0
    MVNS R0, R0
    MOV  R10, R0
    CMP  R0, R10
    BNE  gpr_step9_test_fail
    MVNS R0, R0
    
    CMP  R1, R11
    BNE  gpr_step9_test_fail
    MOV  R11, R0
    MVNS R0, R0
    MOV  R11, R0
    CMP  R0, R11
    BNE  gpr_step9_test_fail
    MVNS R0, R0
    
    CMP  R1, R12
    BNE  gpr_step9_test_fail
    MOV  R12, R0
    MVNS R0, R0
    MOV  R12, R0
    CMP  R0, R12
    BNE  gpr_step9_test_fail
    MVNS R0, R0
    
    POP {R0}
    MSR PRIMASK, R0
    POP {R4-R7}     ; Restore registers
    MOVS R0, #0x00  ; CPUTEST_SUCCESS
    BX LR           ; return to the caller

gpr_step9_test_fail
    POP {R0}
    MSR PRIMASK, R0
    POP {R4-R7}     ; Restore registers
    MOVS R0, #0x01  ; CPUTEST_FAIL
    BX LR           ; return to the caller

    ENDP            ; routine (unrecoverable fault)
    
; ---------intra word test-------------------
; march SS-10 ∨, RWR, DB[3u], DB_BAR[3u]
_diag_gpr_step10 PROC
    EXPORT _diag_gpr_step10

    PUSH {R4-R7}           ; Safe registers
    
    MRS R0, PRIMASK
    PUSH {R0}
    
    CPSID I

    LDR R0, =U32_MARCH_DB
    LDR R0,[R0, #12]
    MOV R1,R0
    MOV R2,R0
    MOV R3,R0
    MOV R4,R0
    MOV R5,R0
    MOV R6,R0
    MOV R7,R0
    MOV R8,R0
    MOV R9,R0
    MOV R10,R0
    MOV R11,R0
    MOV R12,R0
    
    CMP  R0, R12
    BNE  gpr_step10_test_fail
    MVNS R0, R0
    MOV  R12, R0
    CMP  R0, R12
    BNE  gpr_step10_test_fail
    MVNS R0, R0
    
    CMP  R0, R11
    BNE  gpr_step10_test_fail
    MVNS R0, R0
    MOV  R11, R0
    CMP  R0, R11
    BNE  gpr_step10_test_fail
    MVNS R0, R0
    
    CMP  R0, R10
    BNE  gpr_step10_test_fail
    MVNS R0, R0
    MOV  R10, R0
    CMP  R0, R10
    BNE  gpr_step10_test_fail
    MVNS R0, R0
    
    CMP  R0, R9
    BNE  gpr_step10_test_fail
    MVNS R0, R0
    MOV  R9, R0
    CMP  R0, R9
    BNE  gpr_step10_test_fail
    MVNS R0, R0
    
    CMP  R0, R8
    BNE  gpr_step10_test_fail
    MVNS R0, R0
    MOV  R8, R0
    CMP  R0, R8
    BNE  gpr_step10_test_fail
    MVNS R0, R0
    
    CMP  R0, R7
    BNE  gpr_step10_test_fail
    MVNS R0, R0
    MOV  R7, R0
    CMP  R0, R7
    BNE  gpr_step10_test_fail
    MVNS R0, R0
    
    CMP  R0, R6
    BNE  gpr_step10_test_fail
    MVNS R0, R0
    MOV  R6, R0
    CMP  R0, R6
    BNE  gpr_step10_test_fail
    MVNS R0, R0
    
    CMP  R0, R5
    BNE  gpr_step10_test_fail
    MVNS R0, R0
    MOV  R5, R0
    CMP  R0, R5
    BNE  gpr_step10_test_fail
    MVNS R0, R0
    
    CMP  R0, R4
    BNE  gpr_step10_test_fail
    MVNS R0, R0
    MOV  R4, R0
    CMP  R0, R4
    BNE  gpr_step10_test_fail
    MVNS R0, R0

    CMP  R0, R3
    BNE  gpr_step10_test_fail
    MVNS R0, R0
    MOV  R3, R0
    CMP  R0, R3
    BNE  gpr_step10_test_fail
    MVNS R0, R0
    
    CMP  R0, R2
    BNE  gpr_step10_test_fail
    MVNS R0, R0
    MOV  R2, R0
    CMP  R0, R2
    BNE  gpr_step10_test_fail
    MVNS R0, R0
    
    CMP  R0, R1
    BNE  gpr_step10_test_fail
    MVNS R0, R0
    MOV  R1, R0
    CMP  R0, R1
    BNE  gpr_step10_test_fail
    MVNS R0, R0
    
    POP {R0}
    MSR PRIMASK, R0
    POP {R4-R7}     ; Restore registers
    MOVS R0, #0x00  ; CPUTEST_SUCCESS
    BX LR           ; return to the caller
    LTORG
gpr_step10_test_fail
    POP {R0}
    MSR PRIMASK, R0
    POP {R4-R7}     ; Restore registers
    MOVS R0, #0x01  ; CPUTEST_FAIL
    BX LR           ; return to the caller

    ENDP            ; routine (unrecoverable fault)
    
; ---------intra word test-------------------
; march SS-11 ∧ , RWWR, DB_BAR[3u], DB_BAR[4u], DB[4u]
_diag_gpr_step11 PROC
    EXPORT _diag_gpr_step11

    PUSH {R4-R7}           ; Safe registers
    
    MRS R0, PRIMASK
    PUSH {R0}
    
    CPSID I

    LDR R0, =U32_MARCH_DB_BAR
    LDR R0,[R0, #12]
    MOV R1,R0
    MOV R2,R0
    MOV R3,R0
    MOV R4,R0
    MOV R5,R0
    MOV R6,R0
    MOV R7,R0
    MOV R8,R0
    MOV R9,R0
    MOV R10,R0
    MOV R11,R0
    MOV R12,R0
    
    CMP  R0, R1
    BNE  gpr_step11_test_fail
    LDR  R0, =U32_MARCH_DB_BAR
    LDR  R0,[R0, #16]
    MOV  R1, R0
    MVNS R0, R0
    MOV  R1, R0
    CMP  R0, R1
    BNE  gpr_step11_test_fail
    MVNS R0, R0
    
    LDR R0, =U32_MARCH_DB_BAR
    LDR R1,[R0, #12]
    LDR  R0, =U32_MARCH_DB_BAR
    LDR  R0,[R0, #16]
	
    CMP  R1, R2
    BNE  gpr_step11_test_fail
    MOV  R2, R0
    MVNS R0, R0
    MOV  R2, R0
    CMP  R0, R2
    BNE  gpr_step11_test_fail
    MVNS R0, R0
    
    CMP  R1, R3
    BNE  gpr_step11_test_fail
    MOV  R3, R0
    MVNS R0, R0
    MOV  R3, R0
    CMP  R0, R3
    BNE  gpr_step11_test_fail
    MVNS R0, R0
    
    CMP  R1, R4
    BNE  gpr_step11_test_fail
    MOV  R4, R0
    MVNS R0, R0
    MOV  R4, R0
    CMP  R0, R4
    BNE  gpr_step11_test_fail
    MVNS R0, R0
    
    CMP  R1, R5
    BNE  gpr_step11_test_fail
    MOV  R5, R0
    MVNS R0, R0
    MOV  R5, R0
    CMP  R0, R5
    BNE  gpr_step11_test_fail
    MVNS R0, R0
    
    CMP  R1, R6
    BNE  gpr_step11_test_fail
    MOV  R6, R0
    MVNS R0, R0
    MOV  R6, R0
    CMP  R0, R6
    BNE  gpr_step11_test_fail
    MVNS R0, R0
    
    CMP  R1, R7
    BNE  gpr_step11_test_fail
    MOV  R7, R0
    MVNS R0, R0
    MOV  R7, R0
    CMP  R0, R7
    BNE  gpr_step11_test_fail
    MVNS R0, R0
    
    CMP  R1, R8
    BNE  gpr_step11_test_fail
    MOV  R8, R0
    MVNS R0, R0
    MOV  R8, R0
    CMP  R0, R8
    BNE  gpr_step11_test_fail
    MVNS R0, R0
    
    CMP  R1, R9
    BNE  gpr_step11_test_fail
    MOV  R9, R0
    MVNS R0, R0
    MOV  R9, R0
    CMP  R0, R9
    BNE  gpr_step11_test_fail
    MVNS R0, R0

    CMP  R1, R10
    BNE  gpr_step11_test_fail
    MOV  R10, R0
    MVNS R0, R0
    MOV  R10, R0
    CMP  R0, R10
    BNE  gpr_step11_test_fail
    MVNS R0, R0
    
    CMP  R1, R11
    BNE  gpr_step11_test_fail
    MOV  R11, R0
    MVNS R0, R0
    MOV  R11, R0
    CMP  R0, R11
    BNE  gpr_step11_test_fail
    MVNS R0, R0
    
    CMP  R1, R12
    BNE  gpr_step11_test_fail
    MOV  R12, R0
    MVNS R0, R0
    MOV  R12, R0
    CMP  R0, R12
    BNE  gpr_step11_test_fail
    MVNS R0, R0
    
    POP {R0}
    MSR PRIMASK, R0
    POP {R4-R7}     ; Restore registers
    MOVS R0, #0x00  ; CPUTEST_SUCCESS
    BX LR           ; return to the caller
    
gpr_step11_test_fail
		NOP;
    POP {R0}
    MSR PRIMASK, R0
    POP {R4-R7}     ; Restore registers
    MOVS R0, #0x01  ; CPUTEST_FAIL
    BX LR           ; return to the caller
    
    LTORG
    
    ENDP            ; routine (unrecoverable fault)
    
; ---------intra word test-------------------
; march SS-12 ∨ , RWR, DB[4u], DB_BAR[4u]
_diag_gpr_step12 PROC
    EXPORT _diag_gpr_step12

    PUSH {R4-R7}           ; Safe registers
    
    MRS R0, PRIMASK
    PUSH {R0}
    
    CPSID I

    LDR R0, =U32_MARCH_DB
    LDR R0,[R0, #16]
    MOV R1,R0
    MOV R2,R0
    MOV R3,R0
    MOV R4,R0
    MOV R5,R0
    MOV R6,R0
    MOV R7,R0
    MOV R8,R0
    MOV R9,R0
    MOV R10,R0
    MOV R11,R0
    MOV R12,R0
    
    CMP  R0, R12
    BNE  gpr_step12_test_fail
    MVNS R0, R0
    MOV  R12, R0
    CMP  R0, R12
    BNE  gpr_step12_test_fail
    MVNS R0, R0
    
    CMP  R0, R11
    BNE  gpr_step12_test_fail
    MVNS R0, R0
    MOV  R11, R0
    CMP  R0, R11
    BNE  gpr_step12_test_fail
    MVNS R0, R0
    
    CMP  R0, R10
    BNE  gpr_step12_test_fail
    MVNS R0, R0
    MOV  R10, R0
    CMP  R0, R10
    BNE  gpr_step12_test_fail
    MVNS R0, R0
    
    CMP  R0, R9
    BNE  gpr_step12_test_fail
    MVNS R0, R0
    MOV  R9, R0
    CMP  R0, R9
    BNE  gpr_step12_test_fail
    MVNS R0, R0
    
    CMP  R0, R8
    BNE  gpr_step12_test_fail
    MVNS R0, R0
    MOV  R8, R0
    CMP  R0, R8
    BNE  gpr_step12_test_fail
    MVNS R0, R0
    
    CMP  R0, R7
    BNE  gpr_step12_test_fail
    MVNS R0, R0
    MOV  R7, R0
    CMP  R0, R7
    BNE  gpr_step12_test_fail
    MVNS R0, R0
    
    CMP  R0, R6
    BNE  gpr_step12_test_fail
    MVNS R0, R0
    MOV  R6, R0
    CMP  R0, R6
    BNE  gpr_step12_test_fail
    MVNS R0, R0
    
    CMP  R0, R5
    BNE  gpr_step12_test_fail
    MVNS R0, R0
    MOV  R5, R0
    CMP  R0, R5
    BNE  gpr_step12_test_fail
    MVNS R0, R0
    
    CMP  R0, R4
    BNE  gpr_step12_test_fail
    MVNS R0, R0
    MOV  R4, R0
    CMP  R0, R4
    BNE  gpr_step12_test_fail
    MVNS R0, R0

    CMP  R0, R3
    BNE  gpr_step12_test_fail
    MVNS R0, R0
    MOV  R3, R0
    CMP  R0, R3
    BNE  gpr_step12_test_fail
    MVNS R0, R0
    
    CMP  R0, R2
    BNE  gpr_step12_test_fail
    MVNS R0, R0
    MOV  R2, R0
    CMP  R0, R2
    BNE  gpr_step12_test_fail
    MVNS R0, R0
    
    CMP  R0, R1
    BNE  gpr_step12_test_fail
    MVNS R0, R0
    MOV  R1, R0
    CMP  R0, R1
    BNE  gpr_step12_test_fail
    MVNS R0, R0
    
    POP {R0}
    MSR PRIMASK, R0
    POP {R4-R7}     ; Restore registers
    MOVS R0, #0x00  ; CPUTEST_SUCCESS
    BX LR           ; return to the caller
    
gpr_step12_test_fail
    POP {R0}
    MSR PRIMASK, R0
    POP {R4-R7}     ; Restore registers
    MOVS R0, #0x01  ; CPUTEST_FAIL
    BX LR           ; return to the caller
    
    ENDP            ; routine (unrecoverable fault)
    
; ---------intra word test-------------------
; march SS-13 ∧ , RWWR, DB_BAR[4u], DB_BAR[5u], DB[5u]
_diag_gpr_step13 PROC
    EXPORT _diag_gpr_step13

    PUSH {R4-R7}           ; Safe registers
    
    MRS R0, PRIMASK
    PUSH {R0}
    
    CPSID I

    LDR R0, =U32_MARCH_DB_BAR
    LDR R0,[R0, #16]
    MOV R1,R0
    MOV R2,R0
    MOV R3,R0
    MOV R4,R0
    MOV R5,R0
    MOV R6,R0
    MOV R7,R0
    MOV R8,R0
    MOV R9,R0
    MOV R10,R0
    MOV R11,R0
    MOV R12,R0
    
    CMP  R0, R1
    BNE  gpr_step13_test_fail
    LDR  R0, =U32_MARCH_DB_BAR
    LDR  R0,[R0, #20]
    MOV  R1, R0
    MVNS R0, R0
    MOV  R1, R0
    CMP  R0, R1
    BNE  gpr_step13_test_fail
    MVNS R0, R0
    
    LDR R0, =U32_MARCH_DB_BAR
    LDR R1,[R0, #16]
    LDR  R0, =U32_MARCH_DB_BAR
    LDR  R0,[R0, #20]
	
    CMP  R1, R2
    BNE  gpr_step13_test_fail
    MOV  R2, R0
    MVNS R0, R0
    MOV  R2, R0
    CMP  R0, R2
    BNE  gpr_step13_test_fail
    MVNS R0, R0
    
    CMP  R1, R3
    BNE  gpr_step13_test_fail
    MOV  R3, R0
    MVNS R0, R0
    MOV  R3, R0
    CMP  R0, R3
    BNE  gpr_step13_test_fail
    MVNS R0, R0
    
    CMP  R1, R4
    BNE  gpr_step13_test_fail
    MOV  R4, R0
    MVNS R0, R0
    MOV  R4, R0
    CMP  R0, R4
    BNE  gpr_step13_test_fail
    MVNS R0, R0
    
    CMP  R1, R5
    BNE  gpr_step13_test_fail
    MOV  R5, R0
    MVNS R0, R0
    MOV  R5, R0
    CMP  R0, R5
    BNE  gpr_step13_test_fail
    MVNS R0, R0
    
    CMP  R1, R6
    BNE  gpr_step13_test_fail
    MOV  R6, R0
    MVNS R0, R0
    MOV  R6, R0
    CMP  R0, R6
    BNE  gpr_step13_test_fail
    MVNS R0, R0
    
    CMP  R1, R7
    BNE  gpr_step13_test_fail
    MOV  R7, R0
    MVNS R0, R0
    MOV  R7, R0
    CMP  R0, R7
    BNE  gpr_step13_test_fail
    MVNS R0, R0
    
    CMP  R1, R8
    BNE  gpr_step13_test_fail
    MOV  R8, R0
    MVNS R0, R0
    MOV  R8, R0
    CMP  R0, R8
    BNE  gpr_step13_test_fail
    MVNS R0, R0
    
    CMP  R1, R9
    BNE  gpr_step13_test_fail
    MOV  R9, R0
    MVNS R0, R0
    MOV  R9, R0
    CMP  R0, R9
    BNE  gpr_step13_test_fail
    MVNS R0, R0

    CMP  R1, R10
    BNE  gpr_step13_test_fail
    MOV  R10, R0
    MVNS R0, R0
    MOV  R10, R0
    CMP  R0, R10
    BNE  gpr_step13_test_fail
    MVNS R0, R0
    
    CMP  R1, R11
    BNE  gpr_step13_test_fail
    MOV  R11, R0
    MVNS R0, R0
    MOV  R11, R0
    CMP  R0, R11
    BNE  gpr_step13_test_fail
    MVNS R0, R0
    
    CMP  R1, R12
    BNE  gpr_step13_test_fail
    MOV  R12, R0
    MVNS R0, R0
    MOV  R12, R0
    CMP  R0, R12
    BNE  gpr_step13_test_fail
    MVNS R0, R0
    
    POP {R0}
    MSR PRIMASK, R0
    POP {R4-R7}     ; Restore registers
    MOVS R0, #0x00  ; CPUTEST_SUCCESS
    BX LR           ; return to the caller
    
gpr_step13_test_fail
    POP {R0}
    MSR PRIMASK, R0
    POP {R4-R7}     ; Restore registers
    MOVS R0, #0x01  ; CPUTEST_FAIL
    BX LR           ; return to the caller
    
    LTORG
    
    ENDP            ; routine (unrecoverable fault)
    
; ---------intra word test-------------------
; march SS-14 ∨ , RWR, DB[5u], DB_BAR[5u]
_diag_gpr_step14 PROC
    EXPORT _diag_gpr_step14

    PUSH {R4-R7}           ; Safe registers
    
    MRS R0, PRIMASK
    PUSH {R0}
    
    CPSID I

    LDR R0, =U32_MARCH_DB
    LDR R0,[R0, #20]
    MOV R1,R0
    MOV R2,R0
    MOV R3,R0
    MOV R4,R0
    MOV R5,R0
    MOV R6,R0
    MOV R7,R0
    MOV R8,R0
    MOV R9,R0
    MOV R10,R0
    MOV R11,R0
    MOV R12,R0
    
    CMP  R0, R12
    BNE  gpr_step14_test_fail
    MVNS R0, R0
    MOV  R12, R0
    CMP  R0, R12
    BNE  gpr_step14_test_fail
    MVNS R0, R0
    
    CMP  R0, R11
    BNE  gpr_step14_test_fail
    MVNS R0, R0
    MOV  R11, R0
    CMP  R0, R11
    BNE  gpr_step14_test_fail
    MVNS R0, R0
    
    CMP  R0, R10
    BNE  gpr_step14_test_fail
    MVNS R0, R0
    MOV  R10, R0
    CMP  R0, R10
    BNE  gpr_step14_test_fail
    MVNS R0, R0
    
    CMP  R0, R9
    BNE  gpr_step14_test_fail
    MVNS R0, R0
    MOV  R9, R0
    CMP  R0, R9
    BNE  gpr_step14_test_fail
    MVNS R0, R0
    
    CMP  R0, R8
    BNE  gpr_step14_test_fail
    MVNS R0, R0
    MOV  R8, R0
    CMP  R0, R8
    BNE  gpr_step14_test_fail
    MVNS R0, R0
    
    CMP  R0, R7
    BNE  gpr_step14_test_fail
    MVNS R0, R0
    MOV  R7, R0
    CMP  R0, R7
    BNE  gpr_step14_test_fail
    MVNS R0, R0
    
    CMP  R0, R6
    BNE  gpr_step14_test_fail
    MVNS R0, R0
    MOV  R6, R0
    CMP  R0, R6
    BNE  gpr_step14_test_fail
    MVNS R0, R0
    
    CMP  R0, R5
    BNE  gpr_step14_test_fail
    MVNS R0, R0
    MOV  R5, R0
    CMP  R0, R5
    BNE  gpr_step14_test_fail
    MVNS R0, R0
    
    CMP  R0, R4
    BNE  gpr_step14_test_fail
    MVNS R0, R0
    MOV  R4, R0
    CMP  R0, R4
    BNE  gpr_step14_test_fail
    MVNS R0, R0

    CMP  R0, R3
    BNE  gpr_step14_test_fail
    MVNS R0, R0
    MOV  R3, R0
    CMP  R0, R3
    BNE  gpr_step14_test_fail
    MVNS R0, R0
    
    CMP  R0, R2
    BNE  gpr_step14_test_fail
    MVNS R0, R0
    MOV  R2, R0
    CMP  R0, R2
    BNE  gpr_step14_test_fail
    MVNS R0, R0
    
    CMP  R0, R1
    BNE  gpr_step14_test_fail
    MVNS R0, R0
    MOV  R1, R0
    CMP  R0, R1
    BNE  gpr_step14_test_fail
    MVNS R0, R0
    
    POP {R0}
    MSR PRIMASK, R0
    POP {R4-R7}     ; Restore registers
    MOVS R0, #0x00  ; CPUTEST_SUCCESS
    BX LR           ; return to the caller
    
gpr_step14_test_fail
    POP {R0}
    MSR PRIMASK, R0
    POP {R4-R7}     ; Restore registers
    MOVS R0, #0x01  ; CPUTEST_FAIL
    BX LR           ; return to the caller
    
    ENDP            ; routine (unrecoverable fault)
    
; ---------intra word test-------------------
; march SS-15 ∧ , RWWR, DB_BAR[5u], DB_BAR[6u], DB[6u]
_diag_gpr_step15 PROC
    EXPORT _diag_gpr_step15

    PUSH {R4-R7}           ; Safe registers
    
    MRS R0, PRIMASK
    PUSH {R0}
    
    CPSID I

    LDR R0, =U32_MARCH_DB_BAR
    LDR R0,[R0, #20]
    MOV R1,R0
    MOV R2,R0
    MOV R3,R0
    MOV R4,R0
    MOV R5,R0
    MOV R6,R0
    MOV R7,R0
    MOV R8,R0
    MOV R9,R0
    MOV R10,R0
    MOV R11,R0
    MOV R12,R0
    
    CMP  R0, R1
    BNE  gpr_step15_test_fail
    LDR  R0, =U32_MARCH_DB_BAR
    LDR  R0,[R0, #24]
    MOV  R1, R0
    MVNS R0, R0
    MOV  R1, R0
    CMP  R0, R1
    BNE  gpr_step15_test_fail
    MVNS R0, R0
    
    LDR  R0, =U32_MARCH_DB_BAR
    LDR  R1,[R0, #20]
    LDR  R0, =U32_MARCH_DB_BAR
    LDR  R0,[R0, #24]
	
    CMP  R1, R2
    BNE  gpr_step15_test_fail
    MOV  R2, R0
    MVNS R0, R0
    MOV  R2, R0
    CMP  R0, R2
    BNE  gpr_step15_test_fail
    MVNS R0, R0
    
    CMP  R1, R3
    BNE  gpr_step15_test_fail
    MOV  R3, R0
    MVNS R0, R0
    MOV  R3, R0
    CMP  R0, R3
    BNE  gpr_step15_test_fail
    MVNS R0, R0
    
    CMP  R1, R4
    BNE  gpr_step15_test_fail
    MOV  R4, R0
    MVNS R0, R0
    MOV  R4, R0
    CMP  R0, R4
    BNE  gpr_step15_test_fail
    MVNS R0, R0
    
    CMP  R1, R5
    BNE  gpr_step15_test_fail
    MOV  R5, R0
    MVNS R0, R0
    MOV  R5, R0
    CMP  R0, R5
    BNE  gpr_step15_test_fail
    MVNS R0, R0
    
    CMP  R1, R6
    BNE  gpr_step15_test_fail
    MOV  R6, R0
    MVNS R0, R0
    MOV  R6, R0
    CMP  R0, R6
    BNE  gpr_step15_test_fail
    MVNS R0, R0
    
    CMP  R1, R7
    BNE  gpr_step15_test_fail
    MOV  R7, R0
    MVNS R0, R0
    MOV  R7, R0
    CMP  R0, R7
    BNE  gpr_step15_test_fail
    MVNS R0, R0
    
    CMP  R1, R8
    BNE  gpr_step15_test_fail
    MOV  R8, R0
    MVNS R0, R0
    MOV  R8, R0
    CMP  R0, R8
    BNE  gpr_step15_test_fail
    MVNS R0, R0
    
    CMP  R1, R9
    BNE  gpr_step15_test_fail
    MOV  R9, R0
    MVNS R0, R0
    MOV  R9, R0
    CMP  R0, R9
    BNE  gpr_step15_test_fail
    MVNS R0, R0

    CMP  R1, R10
    BNE  gpr_step15_test_fail
    MOV  R10, R0
    MVNS R0, R0
    MOV  R10, R0
    CMP  R0, R10
    BNE  gpr_step15_test_fail
    MVNS R0, R0
    
    CMP  R1, R11
    BNE  gpr_step15_test_fail
    MOV  R11, R0
    MVNS R0, R0
    MOV  R11, R0
    CMP  R0, R11
    BNE  gpr_step15_test_fail
    MVNS R0, R0
    
    CMP  R1, R12
    BNE  gpr_step15_test_fail
    MOV  R12, R0
    MVNS R0, R0
    MOV  R12, R0
    CMP  R0, R12
    BNE  gpr_step15_test_fail
    MVNS R0, R0
    
    POP {R0}
    MSR PRIMASK, R0
    POP {R4-R7}     ; Restore registers
    MOVS R0, #0x00  ; CPUTEST_SUCCESS
    BX LR           ; return to the caller
    
gpr_step15_test_fail
    POP {R0}
    MSR PRIMASK, R0
    POP {R4-R7}     ; Restore registers
    MOVS R0, #0x01  ; CPUTEST_FAIL
    BX LR           ; return to the caller
    
    LTORG
    
    ENDP            ; routine (unrecoverable fault)
	
; ---------intra word test-------------------
; march SS-16 ∨ , RWR, DB[6u], DB_BAR[6u]
_diag_gpr_step16 PROC
    EXPORT _diag_gpr_step16

    PUSH {R4-R7}           ; Safe registers
    
    MRS R0, PRIMASK
    PUSH {R0}
    
    CPSID I

    LDR R0, =U32_MARCH_DB
    LDR R0,[R0, #24]
    MOV R1,R0
    MOV R2,R0
    MOV R3,R0
    MOV R4,R0
    MOV R5,R0
    MOV R6,R0
    MOV R7,R0
    MOV R8,R0
    MOV R9,R0
    MOV R10,R0
    MOV R11,R0
    MOV R12,R0
    
    CMP  R0, R12
    BNE  gpr_step16_test_fail
    MVNS R0, R0
    MOV  R12, R0
    CMP  R0, R12
    BNE  gpr_step16_test_fail
    MVNS R0, R0
    
    CMP  R0, R11
    BNE  gpr_step16_test_fail
    MVNS R0, R0
    MOV  R11, R0
    CMP  R0, R11
    BNE  gpr_step16_test_fail
    MVNS R0, R0
    
    CMP  R0, R10
    BNE  gpr_step16_test_fail
    MVNS R0, R0
    MOV  R10, R0
    CMP  R0, R10
    BNE  gpr_step16_test_fail
    MVNS R0, R0
    
    CMP  R0, R9
    BNE  gpr_step16_test_fail
    MVNS R0, R0
    MOV  R9, R0
    CMP  R0, R9
    BNE  gpr_step16_test_fail
    MVNS R0, R0
    
    CMP  R0, R8
    BNE  gpr_step16_test_fail
    MVNS R0, R0
    MOV  R8, R0
    CMP  R0, R8
    BNE  gpr_step16_test_fail
    MVNS R0, R0
    
    CMP  R0, R7
    BNE  gpr_step16_test_fail
    MVNS R0, R0
    MOV  R7, R0
    CMP  R0, R7
    BNE  gpr_step16_test_fail
    MVNS R0, R0
    
    CMP  R0, R6
    BNE  gpr_step16_test_fail
    MVNS R0, R0
    MOV  R6, R0
    CMP  R0, R6
    BNE  gpr_step16_test_fail
    MVNS R0, R0
    
    CMP  R0, R5
    BNE  gpr_step16_test_fail
    MVNS R0, R0
    MOV  R5, R0
    CMP  R0, R5
    BNE  gpr_step16_test_fail
    MVNS R0, R0
    
    CMP  R0, R4
    BNE  gpr_step16_test_fail
    MVNS R0, R0
    MOV  R4, R0
    CMP  R0, R4
    BNE  gpr_step16_test_fail
    MVNS R0, R0

    CMP  R0, R3
    BNE  gpr_step16_test_fail
    MVNS R0, R0
    MOV  R3, R0
    CMP  R0, R3
    BNE  gpr_step16_test_fail
    MVNS R0, R0
    
    CMP  R0, R2
    BNE  gpr_step16_test_fail
    MVNS R0, R0
    MOV  R2, R0
    CMP  R0, R2
    BNE  gpr_step16_test_fail
    MVNS R0, R0
    
    CMP  R0, R1
    BNE  gpr_step16_test_fail
    MVNS R0, R0
    MOV  R1, R0
    CMP  R0, R1
    BNE  gpr_step16_test_fail
    MVNS R0, R0
    
    POP {R0}
    MSR PRIMASK, R0
    POP {R4-R7}     ; Restore registers
    MOVS R0, #0x00  ; CPUTEST_SUCCESS
    BX LR           ; return to the caller
    
gpr_step16_test_fail
    POP {R0}
    MSR PRIMASK, R0
    POP {R4-R7}     ; Restore registers
    MOVS R0, #0x01  ; CPUTEST_FAIL
    BX LR           ; return to the caller

    ENDP            ; routine (unrecoverable fault)
    
; ---------intra word test-------------------
; march SS-17 ∧ , RWWR, DB_BAR[6u], DB_BAR[7u], DB[7u]
_diag_gpr_step17 PROC
    EXPORT _diag_gpr_step17

    PUSH {R4-R7}           ; Safe registers
    
    MRS R0, PRIMASK
    PUSH {R0}
    
    CPSID I

    LDR R0, =U32_MARCH_DB_BAR
    LDR R0,[R0, #24]
    MOV R1,R0
    MOV R2,R0
    MOV R3,R0
    MOV R4,R0
    MOV R5,R0
    MOV R6,R0
    MOV R7,R0
    MOV R8,R0
    MOV R9,R0
    MOV R10,R0
    MOV R11,R0
    MOV R12,R0
    
    CMP  R0, R1
    BNE  gpr_step17_test_fail
    LDR  R0, =U32_MARCH_DB_BAR
    LDR  R0,[R0, #28]
    MOV  R1, R0
    MVNS R0, R0
    MOV  R1, R0
    CMP  R0, R1
    BNE  gpr_step17_test_fail
    MVNS R0, R0
    
    LDR R0, =U32_MARCH_DB_BAR
    LDR R1,[R0, #24]
    LDR  R0, =U32_MARCH_DB_BAR
    LDR  R0,[R0, #28]
	
    CMP  R1, R2
    BNE  gpr_step17_test_fail
    MOV  R2, R0
    MVNS R0, R0
    MOV  R2, R0
    CMP  R0, R2
    BNE  gpr_step17_test_fail
    MVNS R0, R0
    
    CMP  R1, R3
    BNE  gpr_step17_test_fail
    MOV  R3, R0
    MVNS R0, R0
    MOV  R3, R0
    CMP  R0, R3
    BNE  gpr_step17_test_fail
    MVNS R0, R0
    
    CMP  R1, R4
    BNE  gpr_step17_test_fail
    MOV  R4, R0
    MVNS R0, R0
    MOV  R4, R0
    CMP  R0, R4
    BNE  gpr_step17_test_fail
    MVNS R0, R0
    
    CMP  R1, R5
    BNE  gpr_step17_test_fail
    MOV  R5, R0
    MVNS R0, R0
    MOV  R5, R0
    CMP  R0, R5
    BNE  gpr_step17_test_fail
    MVNS R0, R0
    
    CMP  R1, R6
    BNE  gpr_step17_test_fail
    MOV  R6, R0
    MVNS R0, R0
    MOV  R6, R0
    CMP  R0, R6
    BNE  gpr_step17_test_fail
    MVNS R0, R0
    
    CMP  R1, R7
    BNE  gpr_step17_test_fail
    MOV  R7, R0
    MVNS R0, R0
    MOV  R7, R0
    CMP  R0, R7
    BNE  gpr_step17_test_fail
    MVNS R0, R0
    
    CMP  R1, R8
    BNE  gpr_step17_test_fail
    MOV  R8, R0
    MVNS R0, R0
    MOV  R8, R0
    CMP  R0, R8
    BNE  gpr_step17_test_fail
    MVNS R0, R0
    
    CMP  R1, R9
    BNE  gpr_step17_test_fail
    MOV  R9, R0
    MVNS R0, R0
    MOV  R9, R0
    CMP  R0, R9
    BNE  gpr_step17_test_fail
    MVNS R0, R0

    CMP  R1, R10
    BNE  gpr_step17_test_fail
    MOV  R10, R0
    MVNS R0, R0
    MOV  R10, R0
    CMP  R0, R10
    BNE  gpr_step17_test_fail
    MVNS R0, R0
    
    CMP  R1, R11
    BNE  gpr_step17_test_fail
    MOV  R11, R0
    MVNS R0, R0
    MOV  R11, R0
    CMP  R0, R11
    BNE  gpr_step17_test_fail
    MVNS R0, R0
    
    CMP  R1, R12
    BNE  gpr_step17_test_fail
    MOV  R12, R0
    MVNS R0, R0
    MOV  R12, R0
    CMP  R0, R12
    BNE  gpr_step17_test_fail
    MVNS R0, R0
    
    POP {R0}
    MSR PRIMASK, R0
    POP {R4-R7}     ; Restore registers
    MOVS R0, #0x00  ; CPUTEST_SUCCESS
    BX LR           ; return to the caller
    
gpr_step17_test_fail
    POP {R0}
    MSR PRIMASK, R0
    POP {R4-R7}     ; Restore registers
    MOVS R0, #0x01  ; CPUTEST_FAIL
    BX LR           ; return to the caller
    
    LTORG
    
    ENDP            ; routine (unrecoverable fault)
    
; ---------intra word test-------------------
; march SS-18 ∨ , RWR, DB[7u], DB_BAR[7u]
_diag_gpr_step18 PROC
    EXPORT _diag_gpr_step18

    PUSH {R4-R7}           ; Safe registers
    
    MRS R0, PRIMASK
    PUSH {R0}
    
    CPSID I

    LDR R0, =U32_MARCH_DB
    LDR R0,[R0, #28]
    MOV R1,R0
    MOV R2,R0
    MOV R3,R0
    MOV R4,R0
    MOV R5,R0
    MOV R6,R0
    MOV R7,R0
    MOV R8,R0
    MOV R9,R0
    MOV R10,R0
    MOV R11,R0
    MOV R12,R0
    
    CMP  R0, R12
    BNE  gpr_step18_test_fail
    MVNS R0, R0
    MOV  R12, R0
    CMP  R0, R12
    BNE  gpr_step18_test_fail
    MVNS R0, R0
    
    CMP  R0, R11
    BNE  gpr_step18_test_fail
    MVNS R0, R0
    MOV  R11, R0
    CMP  R0, R11
    BNE  gpr_step18_test_fail
    MVNS R0, R0
    
    CMP  R0, R10
    BNE  gpr_step18_test_fail
    MVNS R0, R0
    MOV  R10, R0
    CMP  R0, R10
    BNE  gpr_step18_test_fail
    MVNS R0, R0
    
    CMP  R0, R9
    BNE  gpr_step18_test_fail
    MVNS R0, R0
    MOV  R9, R0
    CMP  R0, R9
    BNE  gpr_step18_test_fail
    MVNS R0, R0
    
    CMP  R0, R8
    BNE  gpr_step18_test_fail
    MVNS R0, R0
    MOV  R8, R0
    CMP  R0, R8
    BNE  gpr_step18_test_fail
    MVNS R0, R0
    
    CMP  R0, R7
    BNE  gpr_step18_test_fail
    MVNS R0, R0
    MOV  R7, R0
    CMP  R0, R7
    BNE  gpr_step18_test_fail
    MVNS R0, R0
    
    CMP  R0, R6
    BNE  gpr_step18_test_fail
    MVNS R0, R0
    MOV  R6, R0
    CMP  R0, R6
    BNE  gpr_step18_test_fail
    MVNS R0, R0
    
    CMP  R0, R5
    BNE  gpr_step18_test_fail
    MVNS R0, R0
    MOV  R5, R0
    CMP  R0, R5
    BNE  gpr_step18_test_fail
    MVNS R0, R0
    
    CMP  R0, R4
    BNE  gpr_step18_test_fail
    MVNS R0, R0
    MOV  R4, R0
    CMP  R0, R4
    BNE  gpr_step18_test_fail
    MVNS R0, R0

    CMP  R0, R3
    BNE  gpr_step18_test_fail
    MVNS R0, R0
    MOV  R3, R0
    CMP  R0, R3
    BNE  gpr_step18_test_fail
    MVNS R0, R0
    
    CMP  R0, R2
    BNE  gpr_step18_test_fail
    MVNS R0, R0
    MOV  R2, R0
    CMP  R0, R2
    BNE  gpr_step18_test_fail
    MVNS R0, R0
    
    CMP  R0, R1
    BNE  gpr_step18_test_fail
    MVNS R0, R0
    MOV  R1, R0
    CMP  R0, R1
    BNE  gpr_step18_test_fail
    
    CMP  R0, R1
    BNE  gpr_step18_test_fail
    CMP  R0, R2
    BNE  gpr_step18_test_fail
    CMP  R0, R3
    BNE  gpr_step18_test_fail
    CMP  R0, R4
    BNE  gpr_step18_test_fail
    CMP  R0, R5
    BNE  gpr_step18_test_fail
    CMP  R0, R6
    BNE  gpr_step18_test_fail
    CMP  R0, R7
    BNE  gpr_step18_test_fail
    CMP  R0, R8
    BNE  gpr_step18_test_fail
    CMP  R0, R9
    BNE  gpr_step18_test_fail
    CMP  R0, R10
    BNE  gpr_step18_test_fail
    CMP  R0, R11
    BNE  gpr_step18_test_fail
    
    POP {R0}
    MSR PRIMASK, R0
    POP {R4-R7}     ; Restore registers
    MOVS R0, #0x00  ; CPUTEST_SUCCESS
    BX LR           ; return to the caller
    
gpr_step18_test_fail
    POP {R0}
    MSR PRIMASK, R0
    POP {R4-R7}     ; Restore registers
    MOVS R0, #0x01  ; CPUTEST_FAIL
    BX LR           ; return to the caller
    
    LTORG
    
    ENDP            ; routine (unrecoverable fault)
    
    
_diag_psp_step1 PROC
    EXPORT _diag_psp_step1
    
    PUSH {R4-R7}              ; Safe registers
    
    MRS R0, PRIMASK
    PUSH {R0}
    
    CPSID I
    
    ;MRS  R0, PSP
    ;LDR  R1, =U32_MARCH_DB
    ;LDR  R1,[R1]
    ;PUSH R1
    ;LDR  R1, =U32_MARCH_DB
    ;LDR  R1,[R1, #4]
    ;PUSH R1
    ;LDR  R1, =U32_MARCH_DB
    ;LDR  R1,[R1, #8]
    ;PUSH R1
    ;
    ;MRS  R2, PSP
    ;ADDs R1, R0, #12
    ;CMP  R2, R1
    ;BNE  psp_step1_test_fail
    
    MRS  R0,PSP
    
    MOVS R3, #0x3
    MVNS R3, R3
    
    LDR  R1, =U32_MARCH_DB
    LDR  R1, [R1]
    ANDS R1, R3
    LDR  R2, =U32_MARCH_DB_BAR
    LDR  R2, [R2]
    ANDS R2, R3
    MSR  PSP,R1
    MSR  PSP,R2
    MRS  R1,PSP
    CMP  R2, R1
    BNE  psp_step1_test_fail
    MRS  R1,PSP
    CMP  R2, R1
    BNE  psp_step1_test_fail
    
    LDR  R2, =U32_MARCH_DB
    LDR  R2,[R2]
    ANDS R2, R3
    MSR  PSP,R2
    MRS  R1,PSP
    CMP  R2, R1
    BNE  psp_step1_test_fail
    MRS  R1,PSP
    CMP  R2, R1
    BNE  psp_step1_test_fail
    
    LDR  R1, =U32_MARCH_DB_BAR
    LDR  R1,[R1, #4]
    ANDS R1, R3
    LDR  R2, =U32_MARCH_DB
    LDR  R2,[R2, #4]
    ANDS R2, R3
    MSR  PSP,R1
    MSR  PSP,R2
    MRS  R1,PSP
    CMP  R2, R1
    BNE  psp_step1_test_fail
    MRS  R1,PSP
    CMP  R2, R1
    BNE  psp_step1_test_fail
    
    LDR  R2, =U32_MARCH_DB_BAR
    LDR  R2,[R2, #4]
    ANDS R2, R3
    MSR  PSP,R2
    MRS  R1,PSP
    CMP  R2, R1
    BNE  psp_step1_test_fail
    MRS  R1,PSP
    CMP  R2, R1
    BNE  psp_step1_test_fail
    
    LDR  R1, =U32_MARCH_DB_BAR
    LDR  R1,[R1, #8]
    ANDS R1, R3
    LDR  R2, =U32_MARCH_DB
    LDR  R2,[R2, #8]
    ANDS R2, R3
    MSR  PSP,R1
    MSR  PSP,R2
    MRS  R1,PSP
    CMP  R2, R1
    BNE  psp_step1_test_fail
    MRS  R1,PSP
    CMP  R2, R1
    BNE  psp_step1_test_fail
    
    LDR  R2, =U32_MARCH_DB_BAR
    LDR  R2,[R2, #8]
    ANDS R2, R3
    MSR  PSP,R2
    MRS  R1,PSP
    CMP  R2, R1
    BNE  psp_step1_test_fail
    MRS  R1,PSP
    CMP  R2, R1
    BNE  psp_step1_test_fail
    
    LDR  R1, =U32_MARCH_DB_BAR
    LDR  R1,[R1, #12]
    ANDS R1, R3
    LDR  R2, =U32_MARCH_DB
    LDR  R2,[R2, #12]
    ANDS R2, R3
    MSR  PSP,R1
    MSR  PSP,R2
    MRS  R1,PSP
    CMP  R2, R1
    BNE  psp_step1_test_fail
    MRS  R1,PSP
    CMP  R2, R1
    BNE  psp_step1_test_fail
    
    LDR  R2, =U32_MARCH_DB_BAR
    LDR  R2,[R2, #12]
    ANDS R2, R3
    MSR  PSP,R2
    MRS  R1,PSP
    CMP  R2, R1
    BNE  psp_step1_test_fail
    MRS  R1,PSP
    CMP  R2, R1
    BNE  psp_step1_test_fail
    
    MSR  PSP,R0
    POP {R0}
    MSR PRIMASK, R0
    POP {R4-R7}     ; Restore registers
    MOVS R0, #0x00  ; CPUTEST_SUCCESS
    BX LR           ; return to the caller
    
psp_step1_test_fail
    MSR  PSP,R0
    POP {R0}
    MSR PRIMASK, R0
    POP {R4-R7}     ; Restore registers
    MOVS R0, #0x01  ; CPUTEST_FAIL
    BX LR           ; return to the caller

    ENDP
    
_diag_psp_step2 PROC
    EXPORT _diag_psp_step2
    
    PUSH {R4-R7}              ; Safe registers
    
    MRS R0, PRIMASK
    PUSH {R0}
    
    CPSID I
    
    ;MRS  R0, PSP
    ;LDR  R1, =U32_MARCH_DB
    ;LDR  R1,[R1]
    ;PUSH R1
    ;LDR  R1, =U32_MARCH_DB
    ;LDR  R1,[R1, #4]
    ;PUSH R1
    ;LDR  R1, =U32_MARCH_DB
    ;LDR  R1,[R1, #8]
    ;PUSH R1
    ;
    ;MRS  R2, PSP
    ;ADDs R1, R0, #12
    ;CMP  R2, R1
    ;BNE  psp_step2_test_fail
    
    MRS  R0,PSP
    
    MOVS R3, #0x3
    MVNS R3, R3
    
    LDR  R1, =U32_MARCH_DB_BAR
    LDR  R1,[R1, #16]
    ANDS R1, R3
    LDR  R2, =U32_MARCH_DB
    LDR  R2,[R2, #16]
    ANDS R2, R3
    MSR  PSP,R1
    MSR  PSP,R2
    MRS  R1,PSP
    CMP  R2, R1
    BNE  psp_step2_test_fail
    MRS  R1,PSP
    CMP  R2, R1
    BNE  psp_step2_test_fail
    
    LDR  R2, =U32_MARCH_DB_BAR
    LDR  R2,[R2, #16]
    ANDS R2, R3
    MSR  PSP,R2
    MRS  R1,PSP
    CMP  R2, R1
    BNE  psp_step2_test_fail
    MRS  R1,PSP
    CMP  R2, R1
    BNE  psp_step2_test_fail
    
    LDR  R1, =U32_MARCH_DB_BAR
    LDR  R1,[R1, #20]
    ANDS R1, R3
    LDR  R2, =U32_MARCH_DB
    LDR  R2,[R2, #20]
    ANDS R2, R3
    MSR  PSP,R1
    MSR  PSP,R2
    MRS  R1,PSP
    CMP  R2, R1
    BNE  psp_step2_test_fail
    MRS  R1,PSP
    CMP  R2, R1
    BNE  psp_step2_test_fail
    
    LDR  R2, =U32_MARCH_DB_BAR
    LDR  R2,[R2, #20]
    ANDS R2, R3
    MSR  PSP,R2
    MRS  R1,PSP
    CMP  R2, R1
    BNE  psp_step2_test_fail
    MRS  R1,PSP
    CMP  R2, R1
    BNE  psp_step2_test_fail
    
    LDR  R1, =U32_MARCH_DB_BAR
    LDR  R1,[R1, #24]
    ANDS R1, R3
    LDR  R2, =U32_MARCH_DB
    LDR  R2,[R2, #24]
    ANDS R2, R3
    MSR  PSP,R1
    MSR  PSP,R2
    MRS  R1,PSP
    CMP  R2, R1
    BNE  psp_step2_test_fail
    MRS  R1,PSP
    CMP  R2, R1
    BNE  psp_step2_test_fail
    
    LDR  R2, =U32_MARCH_DB_BAR
    LDR  R2,[R2, #24]
    ANDS R2, R3
    MSR  PSP,R2
    MRS  R1,PSP
    CMP  R2, R1
    BNE  psp_step2_test_fail
    MRS  R1,PSP
    CMP  R2, R1
    BNE  psp_step2_test_fail
    
    LDR  R1, =U32_MARCH_DB_BAR
    LDR  R1,[R1, #28]
    ANDS R1, R3
    LDR  R2, =U32_MARCH_DB
    LDR  R2,[R2, #28]
    ANDS R2, R3
    MSR  PSP,R1
    MSR  PSP,R2
    MRS  R1,PSP
    CMP  R2, R1
    BNE  psp_step2_test_fail
    MRS  R1,PSP
    CMP  R2, R1
    BNE  psp_step2_test_fail
    
    LDR  R2, =U32_MARCH_DB_BAR
    LDR  R2,[R2, #28]
    ANDS R2, R3
    MSR  PSP,R2
    MRS  R1,PSP
    CMP  R2, R1
    BNE  psp_step2_test_fail
    MRS  R1,PSP
    CMP  R2, R1
    BNE  psp_step2_test_fail
    
    MSR  PSP,R0
    POP {R0}
    MSR PRIMASK, R0
    POP {R4-R7}     ; Restore registers
    MOVS R0, #0x00  ; CPUTEST_SUCCESS
    BX LR           ; return to the caller
    
psp_step2_test_fail
    MSR  PSP,R0
    POP {R0}
    MSR PRIMASK, R0
    POP {R4-R7}     ; Restore registers
    MOVS R0, #0x01  ; CPUTEST_FAIL
    BX LR           ; return to the caller

    LTORG
        
    ENDP
    
    
_diag_msp_step1 PROC
    EXPORT _diag_msp_step1
    
    PUSH {R4-R7}              ; Safe registers
    
    MRS R0, PRIMASK
    PUSH {R0}
    
    CPSID I
    
    ;MRS  R0, MSP
    ;LDR  R1, =U32_MARCH_DB
    ;LDR  R1,[R1]
    ;PUSH R1
    ;LDR  R1, =U32_MARCH_DB
    ;LDR  R1,[R1, #4]
    ;PUSH R1
    ;LDR  R1, =U32_MARCH_DB
    ;LDR  R1,[R1, #8]
    ;PUSH R1
    ;
    ;MRS  R2, MSP
    ;ADDs R1, R0, #12
    ;CMP  R2, R1
    ;BNE  msp_step1_test_fail
    
    MRS  R0,MSP
    
    MOVS R3, #0x3
    MVNS R3, R3
    
    LDR  R1, =U32_MARCH_DB
    LDR  R1,[R1]
    ANDS R1, R3
    LDR  R2, =U32_MARCH_DB_BAR
    LDR  R2,[R2]
    ANDS R2, R3
    MSR  MSP,R1
    MSR  MSP,R2
    MRS  R1,MSP
    CMP  R2, R1
    BNE  msp_step1_test_fail
    MRS  R1,MSP
    CMP  R2, R1
    BNE  msp_step1_test_fail
    
    LDR  R2, =U32_MARCH_DB
    LDR  R2,[R2]
    ANDS R2, R3
    MSR  MSP,R2
    MRS  R1,MSP
    CMP  R2, R1
    BNE  msp_step1_test_fail
    MRS  R1,MSP
    CMP  R2, R1
    BNE  msp_step1_test_fail
    
    LDR  R1, =U32_MARCH_DB_BAR
    LDR  R1,[R1, #4]
    ANDS R1, R3
    LDR  R2, =U32_MARCH_DB
    LDR  R2,[R2, #4]
    ANDS R2, R3
    MSR  MSP,R1
    MSR  MSP,R2
    MRS  R1,MSP
    CMP  R2, R1
    BNE  msp_step1_test_fail
    MRS  R1,MSP
    CMP  R2, R1
    BNE  msp_step1_test_fail
    
    LDR  R2, =U32_MARCH_DB_BAR
    LDR  R2,[R2, #4]
    ANDS R2, R3
    MSR  MSP,R2
    MRS  R1,MSP
    CMP  R2, R1
    BNE  msp_step1_test_fail
    MRS  R1,MSP
    CMP  R2, R1
    BNE  msp_step1_test_fail
    
    LDR  R1, =U32_MARCH_DB_BAR
    LDR  R1,[R1, #8]
    ANDS R1, R3
    LDR  R2, =U32_MARCH_DB
    LDR  R2,[R2, #8]
    ANDS R2, R3
    MSR  MSP,R1
    MSR  MSP,R2
    MRS  R1,MSP
    CMP  R2, R1
    BNE  msp_step1_test_fail
    MRS  R1,MSP
    CMP  R2, R1
    BNE  msp_step1_test_fail
    
    LDR  R2, =U32_MARCH_DB_BAR
    LDR  R2,[R2, #8]
    ANDS R2, R3
    MSR  MSP,R2
    MRS  R1,MSP
    CMP  R2, R1
    BNE  msp_step1_test_fail
    MRS  R1,MSP
    CMP  R2, R1
    BNE  msp_step1_test_fail
    
    LDR  R1, =U32_MARCH_DB_BAR
    LDR  R1,[R1, #12]
    ANDS R1, R3
    LDR  R2, =U32_MARCH_DB
    LDR  R2,[R2, #12]
    ANDS R2, R3
    MSR  MSP,R1
    MSR  MSP,R2
    MRS  R1,MSP
    CMP  R2, R1
    BNE  msp_step1_test_fail
    MRS  R1,MSP
    CMP  R2, R1
    BNE  msp_step1_test_fail
    
    LDR  R2, =U32_MARCH_DB_BAR
    LDR  R2,[R2, #12]
    ANDS R2, R3
    MSR  MSP,R2
    MRS  R1,MSP
    CMP  R2, R1
    BNE  msp_step1_test_fail
    MRS  R1,MSP
    CMP  R2, R1
    BNE  msp_step1_test_fail
		NOP;
    MSR MSP,R0          ; Restore stack pointer value
    POP {R0}
    MSR PRIMASK, R0
    POP {R4-R7}     ; Restore registers
    MOVS R0, #0x00  ; CPUTEST_SUCCESS
    BX LR           ; return to the caller
	
	LTORG
    
msp_step1_test_fail
    MSR  MSP,R0
    POP {R0}
    MSR PRIMASK, R0
    POP  {R4-R7}    ; Restore registers
    MOVS R0, #0x01  ; CPUTEST_FAIL
    BX   LR         ; return to the caller

    ENDP
    
_diag_msp_step2 PROC
    EXPORT _diag_msp_step2
    
    PUSH {R4-R7}              ; Safe registers
    
    MRS R0, PRIMASK
    PUSH {R0}
    
    CPSID I
    
    ;MRS  R0, MSP
    ;LDR  R1, =U32_MARCH_DB
    ;LDR  R1,[R1]
    ;PUSH R1
    ;LDR  R1, =U32_MARCH_DB
    ;LDR  R1,[R1, #4]
    ;PUSH R1
    ;LDR  R1, =U32_MARCH_DB
    ;LDR  R1,[R1, #8]
    ;PUSH R1
    ;
    ;MRS  R2, MSP
    ;ADDs R1, R0, #12
    ;CMP  R2, R1
    ;BNE  msp_step2_test_fail
    
    MRS  R0,MSP
    
    MOVS R3, #0x3
    MVNS R3, R3
    
    LDR  R1, =U32_MARCH_DB_BAR
    LDR  R1,[R1, #16]
    ANDS R1, R3
    LDR  R2, =U32_MARCH_DB
    LDR  R2,[R2, #16]
    ANDS R2, R3
    MSR  MSP,R1
    MSR  MSP,R2
    MRS  R1,MSP
    CMP  R2, R1
    BNE  msp_step2_test_fail
    MRS  R1,MSP
    CMP  R2, R1
    BNE  msp_step2_test_fail
    
    LDR  R2, =U32_MARCH_DB_BAR
    LDR  R2,[R2, #16]
    ANDS R2, R3
    MSR  MSP,R2
    MRS  R1,MSP
    CMP  R2, R1
    BNE  msp_step2_test_fail
    MRS  R1,MSP
    CMP  R2, R1
    BNE  msp_step2_test_fail
    
    LDR  R1, =U32_MARCH_DB_BAR
    LDR  R1,[R1, #20]
    ANDS R1, R3
    LDR  R2, =U32_MARCH_DB
    LDR  R2,[R2, #20]
    ANDS R2, R3
    MSR  MSP,R1
    MSR  MSP,R2
    MRS  R1,MSP
    CMP  R2, R1
    BNE  msp_step2_test_fail
    MRS  R1,MSP
    CMP  R2, R1
    BNE  msp_step2_test_fail
    
    LDR  R2, =U32_MARCH_DB_BAR
    LDR  R2,[R2, #20]
    ANDS R2, R3
    MSR  MSP,R2
    MRS  R1,MSP
    CMP  R2, R1
    BNE  msp_step2_test_fail
    MRS  R1,MSP
    CMP  R2, R1
    BNE  msp_step2_test_fail
    
    LDR  R1, =U32_MARCH_DB_BAR
    LDR  R1,[R1, #24]
    ANDS R1, R3
    LDR  R2, =U32_MARCH_DB
    LDR  R2,[R2, #24]
    ANDS R2, R3
    MSR  MSP,R1
    MSR  MSP,R2
    MRS  R1,MSP
    CMP  R2, R1
    BNE  msp_step2_test_fail
    MRS  R1,MSP
    CMP  R2, R1
    BNE  msp_step2_test_fail
    
    LDR  R2, =U32_MARCH_DB_BAR
    LDR  R2,[R2, #24]
    ANDS R2, R3
    MSR  MSP,R2
    MRS  R1,MSP
    CMP  R2, R1
    BNE  msp_step2_test_fail
    MRS  R1,MSP
    CMP  R2, R1
    BNE  msp_step2_test_fail
    
    LDR  R1, =U32_MARCH_DB_BAR
    LDR  R1,[R1, #28]
    ANDS R1, R3
    LDR  R2, =U32_MARCH_DB
    LDR  R2,[R2, #28]
    ANDS R2, R3
    MSR  MSP,R1
    MSR  MSP,R2
    MRS  R1,MSP
    CMP  R2, R1
    BNE  msp_step2_test_fail
    MRS  R1,MSP
    CMP  R2, R1
    BNE  msp_step2_test_fail
    
    LDR  R2, =U32_MARCH_DB_BAR
    LDR  R2,[R2, #28]
    ANDS R2, R3
    MSR  MSP,R2
    MRS  R1,MSP
    CMP  R2, R1
    BNE  msp_step2_test_fail
    MRS  R1,MSP
    CMP  R2, R1
    BNE  msp_step2_test_fail

    MSR MSP,R0          ; Restore stack pointer value
    POP {R0}
    MSR PRIMASK, R0
    POP {R4-R7}     ; Restore registers
    MOVS R0, #0x00  ; CPUTEST_SUCCESS
    BX LR           ; return to the caller
    
msp_step2_test_fail
    MSR  MSP,R0
    POP {R0}
    MSR PRIMASK, R0
    POP  {R4-R7}    ; Restore registers
    MOVS R0, #0x01  ; CPUTEST_FAIL
    BX   LR         ; return to the caller

    ENDP
    
    NOP
    NOP
	    NOP
U32_MARK_80 DCD 0x80000000

_diag_flg_reg PROC
    EXPORT _diag_flg_reg
    
    PUSH {R4-R7}              ; Safe registers
    
    MRS R0, PRIMASK
    PUSH {R0}
    
    CPSID I
    
    MOVS R0, #0x00            
    UXTB R0,R0
    ADDS R0,#0              ; Set Z(ero) Flag
    BNE flg_reg_test_fail   ; Fails if Z clear
    BMI flg_reg_test_fail   ; Fails if N is set
    SUBS R0,#1              ; Set N(egative) Flag
    BPL flg_reg_test_fail   ; Fails if N clear
    ADDS R0,#2              ; Set C(arry) Flag and do not set Z
    BCC flg_reg_test_fail   ; Fails if C clear
    BEQ flg_reg_test_fail   ; Fails if Z is set
    BMI flg_reg_test_fail   ; Fails if N is set

    LDR R0,=U32_MARK_80     ; Prepares Overflow test
    LDR R0,[R0]
    ADDS R0, R0, R0         ; Set V(overflow) Flag
    BVC flg_reg_test_fail   ; Fails if V clear

    POP {R0}
    MSR PRIMASK, R0
    POP {R4-R7}     ; Restore registers
    MOVS R0, #0x0   ; CPUTEST_SUCCESS
    BX LR           ; return to the caller
    
flg_reg_test_fail
    POP {R0}
    MSR PRIMASK, R0
    POP {R4-R7}     ; Restore registers
    MOVS R0, #0x1   ; CPUTEST_FAIL
    BX LR           ; return to the caller
    ENDP

diag_istr_aux_fun1 PROC
    MOVS R1, #0xAA
    BX LR           ; return to the caller
    ENDP

_diag_istr_set_step1 PROC
    EXPORT _diag_istr_set_step1
    
    PUSH {R4-R7}   ; Safe registers
    
    MRS R0, PRIMASK
    PUSH {R0}
    
    CPSID I
    
    MOVS R0, #0x00  ; R0 is Instruction test error count
    UXTB R0,R0
    
    ; Branch and control instructions ------------
    B   istr_ok_B           ; Instruction B
    BAL istr_step1_test_fail
    
istr_ok_B
    MOVS R1, #0x55
    MOV  R0, LR
    BL  diag_istr_aux_fun1  ; Instruction BL
    MOV  LR, R0
    CMP R1, #0xAA
    BNE istr_step1_test_fail
    
    MOVS  R1, #0x00
    ADDS R1, #0x00
    BEQ  istr_ok_BEQ        ; Instruction BEQ
    
    BAL istr_step1_test_fail
    
istr_ok_BEQ
    MOVS R1, #0x01
    UXTB R1, R1
    ADDS R1, #0
    BNE  istr_ok_BNE     ; Instruction BNE
    
    BAL  istr_step1_test_fail
    
istr_ok_BNE
    POP {R0}
    MSR PRIMASK, R0
    POP {R4-R7}    ; Restore registers
    MOVS R0, #0x0   ; CPUTEST_SUCCESS
    BX LR           ; Instruction BX, return to the caller
    
istr_step1_test_fail
    POP {R0}
    MSR PRIMASK, R0
    POP {R4-R7}     ; Restore registers
    MOVS R0, #0x1   ; CPUTEST_FAIL
    BLX LR           ; Instruction BLX, return to the caller
    
    NOP ;
    
    ENDP
    
_diag_istr_set_step2 PROC
    EXPORT _diag_istr_set_step2
    
    PUSH {R4-R7}   ; Safe registers
    
    MRS R0, PRIMASK
    PUSH {R0}
    
    CPSID I
    
    ; General data processing instructions ------
    MOVS  R1, #0x0       ; Instruction MOV
    MOVS  R2, #0x0
    MVNS R2, R2       ; R2=0xFFFFFFFF, Instruction MVN
    BICS  R2, R2, R2    ; R2=0x0, Instruction BIC
    CMP  R1, R2
    BNE istr_step2_test_fail
    ;----------
    MOVS  R1, #0x55  ; MOVS
    ADDS  R1, #0x55  ; ADD
    SUBS  R1, #0x11  ; SUB
    CMP  R1, #0x99
    BNE istr_step2_test_fail
    ;----------
    MOVS  R4, #0x55
    MOVS  R3, #0x55
    MOVS  R6, #0
    MVNS R6, R6
    MOVS  R7, #0x55
    ADDS R2, R4, R6 ;R2=0x54, ADDS
    ADCS R3, R3, R7 ;R3=0xAB, ADC
    CMP  R2, #0x54
    BNE istr_step2_test_fail
    CMP  R3, #0xAB
    BNE istr_step2_test_fail
    ;----------
    MOVS  R4, #0x0
    MOVS  R3, #0x55
    MOVS R6, #0xFF
    MVNS R6, R6
    MOVS  R7, #0x00
    SUBS R2, R4, R6 ;R2=0x100, SUBS
    SBCS  R3, R3, R7 ;R3=0x54, SBCS
    MOVS R1, #0xFF
    MOVS R4, #0x01
    ADD  R1, R1, R4
    CMP  R2, R1
    BNE istr_step2_test_fail
    CMP  R3, #0x54
    BNE istr_step2_test_fail
    ;----------
    MOVS  R1, #2
    MOVS  R2, #3
    MULS  R1, R2, R1     ;R1=6, MUL
    CMP  R1, #6
    BNE  istr_step2_test_fail
    ;----------
    MOVS  R1, #0x55
    MOVS  R2, #0xF0
    ANDS R1, R2  ;R1=0x50, ANDS
    MOVS  R2, #0x33
    ORRS R1, R2  ;R1=0x73, ORRS
    MOVS  R2, #0x0F
    EORS R1, R2  ;R1=0x7C, EORS
    MOVS  R2, #0x10
    BICS R1, R2  ;R1=0x6C, BICS
    CMP  R1, #0x6C  ; CMP
    BNE istr_step2_test_fail

    POP {R0}
    MSR PRIMASK, R0
    POP {R4-R7}    ; Restore registers
    MOVS R0, #0x0   ; CPUTEST_SUCCESS
    BX LR           ; return to the caller
    
istr_step2_test_fail
    POP {R0}
    MSR PRIMASK, R0
    POP {R4-R7}     ; Restore registers
    MOVS R0, #0x1   ; CPUTEST_FAIL
    BX LR           ; return to the caller
    
    NOP ;
    
    ENDP
    
    
_diag_istr_set_step3 PROC
    EXPORT _diag_istr_set_step3
    
    PUSH {R4-R7}   ; Safe registers
    
    MRS R0, PRIMASK
    PUSH {R0}
    
    CPSID I
    
    ; General data processing instructions ------
    MOVS  R1, #0x0       ; Instruction MOV
    MOVS  R2, #0x0
    MVNS R2, R2       ; R2=0xFFFFFFFF, Instruction MVN
    BICS  R2, R2, R2    ; R2=0x0, Instruction BIC
    CMP  R1, R2
    BNE istr_step3_test_fail


    POP {R0}
    MSR PRIMASK, R0
    POP {R4-R7}    ; Restore registers
    MOVS R0, #0x0   ; CPUTEST_SUCCESS
    BX LR           ; return to the caller
    
istr_step3_test_fail
    POP {R0}
    MSR PRIMASK, R0
    POP {R4-R7}     ; Restore registers
    MOVS R0, #0x1   ; CPUTEST_FAIL
    BX LR           ; return to the caller
    
    NOP ;
    
    ENDP
    
    
_diag_istr_set_step4 PROC
    EXPORT _diag_istr_set_step4
    
    PUSH {R4-R7}   ; Safe registers
    
    MRS R0, PRIMASK
    PUSH {R0}
    
    CPSID I
    
    ; General data processing instructions ------
    MOVS  R1, #0x0       ; Instruction MOV
    MOVS  R2, #0x0
    MVNS R2, R2       ; R2=0xFFFFFFFF, Instruction MVN
    BICS  R2, R2, R2    ; R2=0x0, Instruction BIC
    CMP  R1, R2
    BNE istr_step4_test_fail


    POP {R0}
    MSR PRIMASK, R0
    POP {R4-R7}    ; Restore registers
    MOVS R0, #0x0   ; CPUTEST_SUCCESS
    BX LR           ; return to the caller
    
istr_step4_test_fail
    POP {R0}
    MSR PRIMASK, R0
    POP {R4-R7}     ; Restore registers
    MOVS R0, #0x1   ; CPUTEST_FAIL
    BX LR           ; return to the caller
    
    NOP ;
    
    ENDP
    
    
_diag_istr_set_step5 PROC
    EXPORT _diag_istr_set_step5
    
    PUSH {R4-R7}   ; Safe registers
    
    MRS R0, PRIMASK
    PUSH {R0}
    
    CPSID I
    
    ; General data processing instructions ------
    MOVS  R1, #0x0       ; Instruction MOV
    MOVS  R2, #0x0
    MVNS R2, R2       ; R2=0xFFFFFFFF, Instruction MVN
    BICS  R2, R2, R2    ; R2=0x0, Instruction BIC
    CMP  R1, R2
    BNE istr_step5_test_fail


    POP {R0}
    MSR PRIMASK, R0
    POP {R4-R7}    ; Restore registers
    MOVS R0, #0x0   ; CPUTEST_SUCCESS
    BX LR           ; return to the caller
    
istr_step5_test_fail
    POP {R0}
    MSR PRIMASK, R0
    POP {R4-R7}     ; Restore registers
    MOVS R0, #0x1   ; CPUTEST_FAIL
    BX LR           ; return to the caller
    
    NOP ;
    
    ENDP
    
    
_diag_istr_set_step6 PROC
    EXPORT _diag_istr_set_step6
    
    PUSH {R4-R7}   ; Safe registers
    
    MRS R0, PRIMASK
    PUSH {R0}
    
    CPSID I
    
    ; Memory access instructions ------
    MOVS  R1, #0x0       ; Instruction MOV
    MOVS  R2, #0x0
    MVNS R2, R2       ; R2=0xFFFFFFFF, Instruction MVN
    BICS  R2, R2, R2    ; R2=0x0, Instruction BIC
    CMP  R1, R2
    BNE istr_step6_test_fail


    POP {R0}
    MSR PRIMASK, R0
    POP {R4-R7}    ; Restore registers
    MOVS R0, #0x0   ; CPUTEST_SUCCESS
    BX LR           ; return to the caller
    
istr_step6_test_fail
    POP {R0}
    MSR PRIMASK, R0
    POP {R4-R7}     ; Restore registers
    MOVS R0, #0x1   ; CPUTEST_FAIL
    BX LR           ; return to the caller
    
    NOP ;
    
    ENDP
    
    
_diag_istr_set_step7 PROC
    EXPORT _diag_istr_set_step7
    
    PUSH {R4-R7}   ; Safe registers
    
    MRS R0, PRIMASK
    PUSH {R0}
    
    CPSID I
    
    ; Miscellaneous instructions ------
    MOVS  R1, #0x0       ; Instruction MOV
    MOVS  R2, #0x0
    MVNS R2, R2       ; R2=0xFFFFFFFF, Instruction MVN
    BICS  R2, R2, R2    ; R2=0x0, Instruction BIC
    CMP  R1, R2
    BNE istr_step7_test_fail


    POP {R0}
    MSR PRIMASK, R0
    POP {R4-R7}    ; Restore registers
    MOVS R0, #0x0   ; CPUTEST_SUCCESS
    BX LR           ; return to the caller
    
istr_step7_test_fail
    POP {R0}
    MSR PRIMASK, R0
    POP {R4-R7}     ; Restore registers
    MOVS R0, #0x1   ; CPUTEST_FAIL
    BX LR           ; return to the caller
    
    NOP ;
    
    ENDP
    
    
_diag_istr_set_step8 PROC
    EXPORT _diag_istr_set_step8
    
    PUSH {R4-R7}   ; Safe registers
    
    MRS R0, PRIMASK
    PUSH {R0}
    
    CPSID I
    
    ; Miscellaneous instructions ------
    MOVS  R1, #0x0       ; Instruction MOV
    MOVS  R2, #0x0
    MVNS R2, R2       ; R2=0xFFFFFFFF, Instruction MVN
    BICS  R2, R2, R2    ; R2=0x0, Instruction BIC
    CMP  R1, R2
    BNE istr_step8_test_fail


    POP {R0}
    MSR PRIMASK, R0
    POP {R4-R7}    ; Restore registers
    MOVS R0, #0x0   ; CPUTEST_SUCCESS
    BX LR           ; return to the caller
    
istr_step8_test_fail
    POP {R0}
    MSR PRIMASK, R0
    POP {R4-R7}     ; Restore registers
    MOVS R0, #0x1   ; CPUTEST_FAIL
    BX LR           ; return to the caller
    
    NOP ;
    
    ENDP
    
        
    END